Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #22728 - Prohibited lookups usage for get_or_create #3793

Closed
wants to merge 1 commit into from

Conversation

coldmind
Copy link
Contributor

Patch proposes how this problem can be solved.
I decided to make this backwards incompatible, because the way django does it now should not be encouraged.

One more thing - ticket is about get_or_create, but I think update_or_create should have the same behavior.

@@ -494,6 +494,10 @@ def _extract_model_params(self, defaults, **kwargs):
if f.attname in lookup:
lookup[f.name] = lookup.pop(f.attname)
params = {k: v for k, v in kwargs.items() if LOOKUP_SEP not in k}
lookup_parameters = set(kwargs.keys()) - set(params.keys())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to compute this if lookup_parameters_allowed is True. I don't know the ORM code enough, so you can ignore my comment if it sounds like a premature optimization:

if not lookup_parameters_allowed:
    lookup_parameters = set(kwargs.keys()) - set(params.keys())
    if lookup_parameters:
        # ...

@timgraham
Copy link
Member

Yes, we can also apply this to update_or_create()

.. warning::

Lookups usage is not allowed for ``get_or_create()``.
If you will try to use it, ``TypeError`` will be raised::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stilted sentence up to the comma, IMHO. Perhaps lead with Attempting to ...?

@timgraham
Copy link
Member

@coldmind, do you have time/interest in following up on this? Was thinking we could offer completing it as a task for the DjangoconEU sprints if not.

@coldmind
Copy link
Contributor Author

coldmind commented Jun 2, 2015

@timgraham, I'm actually on DjangoConEU now, and also will participate in sprints, but we can propose this task for someone else who had not commited to django before.

@coldmind
Copy link
Contributor Author

coldmind commented Jun 4, 2015

New PR: #4779

@coldmind coldmind closed this Jun 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants