Opened 13 years ago

Closed 12 years ago

#2488 closed defect (invalid)

get_for_model building bad SQL

Reported by: jayklehr Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



Running Django's dev server on mysql 4.1.20 and trying to make use of the get_for_model method from the ContentTypes package to get the content type of a model (using the examples laid out in the GenericForeignKey documentation )

Here's the example code from the documentation:

# However, excluding GenericRelations means your lookups have to be a bit more
# explicit.
>>> from django.contrib.contenttypes.models import ContentType
>>> ctype = ContentType.objects.get_for_model(quartz)
>>> TaggedItem.objects.filter(,
[<TaggedItem: clearish>, <TaggedItem: shiny>]

When I run this line:

ctype = ContentType.objects.get_for_model(quartz)

I get this SQL built:

FROM `django_content_type` WHERE (`django_content_type`.`model` = quartz 
AND `django_content_type`.`app_label` = myapp)

MySQL doesn't like having no ticks around the two values 'quartz' and
'myapp' in this case. (My app is actually named "database" right now,
which is a mysql reserved word as well.)

Change History (1)

comment:1 Changed 12 years ago by Simon G. <dev@…>

Resolution: invalid
Status: newclosed

I'm unable to replicate that as of 5776 - can someone reopen this if it's still an issue.

Note: See TracTickets for help on using tickets.
Back to Top