Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#12768 closed Uncategorized (duplicate)

Raw query map problem with some primary keys

Reported by: Reflejo@… Owned by: nobody
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



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 (some) here:

        if skip:
            if in skip:
                raise InvalidQuery('Raw query must include the primary key')

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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).

comment:2 Changed 3 years ago by sklass@…

  • Easy pickings unset
  • Severity set to Normal
  • Type set to Uncategorized
  • UI/UX unset

I appreciate this is a dupe - can you please point us to the ticket#?


Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.