Code

Opened 3 years ago

Closed 3 years ago

#15028 closed (worksforme)

1.2.4 breaks queryset.extra(select={'__double_underscore_field': ...})

Reported by: cdestigter Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

In 1.2.3 this worked fine:

qs = qs.extra(select={'__foo': "1"}).order_by('__foo')

Now in 1.2.4 I get:

FieldError at /test/
Cannot resolve keyword '' into field. Choices are [...]

I believe the solution is to change django/db/models/sql/compiler.py#L371

pieces = name.split(LOOKUP_SEP)

to

pieces = filter(None, name.split(LOOKUP_SEP))

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by cdestigter

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Actually.. that solution is munted since it strips off the underscores :(

Perhaps a regex fix?

We've already worked around this with s/foo/_foo/ ...

comment:2 Changed 3 years ago by cdestigter

  • Has patch unset
  • Patch needs improvement set

comment:3 Changed 3 years ago by russellm

  • Resolution set to worksforme
  • Status changed from new to closed

I can't reproduce this problem on 1.2.3, 1.2.4 or trunk. If you can provide a more complete example that fails, feel free to reopen.

Add Comment

Modify Ticket

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


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

 
Note: See TracTickets for help on using tickets.