#12768 closed Uncategorized (fixed)
Raw query map problem with some primary keys
| Reported by: | Owned by: | nobody | |
|---|---|---|---|
| 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,
I'm trying the new raw query feature and i'm facing this bug:
When my model has primary_key set to some ForeignKey and I try to invoke the raw() method, InvalidQuery('Raw query must include the primary key') is raised.
class ExampleModel(models.Model):
some = models.ForeignKey(SomeOther, primary_key=True)
class Meta:
db_table = 'example_model'
ExampleModel.objects.raw("SELECT some_id FROM example_model")
The problem arise because get_attname_column gives (some_id, some_id) as name/column but then it is compared to _meta.pk.attname (some) here:
if skip:
if self.model._meta.pk.attname in skip:
raise InvalidQuery('Raw query must include the primary key')
Change History (5)
comment:1 by , 16 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
comment:2 by , 14 years ago
| Easy pickings: | unset |
|---|---|
| Severity: | → Normal |
| Type: | → Uncategorized |
| UI/UX: | unset |
I appreciate this is a dupe - can you please point us to the ticket#?
Thanks
comment:3 by , 10 years ago
| Resolution: | duplicate |
|---|---|
| Status: | closed → new |
This is broken again in 1.8. Looks like 0b6f05ede648ce62a5c91c7c38a0a362711f0656 caused the regression.
Here's my attempt at a patch: https://github.com/django/django/pull/5036
This is a dupe of another ticket (that one is labeled as being about model inheritance, but it's really about anyone where attname != name).