Opened 18 years ago

Closed 17 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: dev
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

Description

Hello,

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 http://www.djangoproject.com/documentation/models/generic_relations/ )

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(content_type__pk=ctype.id, object_id=quartz.id)
[<TaggedItem: clearish>, <TaggedItem: shiny>]

When I run this line:

ctype = ContentType.objects.get_for_model(quartz)

I get this SQL built:

SELECT 
`django_content_type`.`id`,`django_content_type`.`name`,`django_content_type`.`app_label`,`django_content_type`.`model` 
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 by Simon G. <dev@…>, 17 years ago

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