-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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 #22936 -- Obsoleted Field.get_prep_lookup()/get_db_prep_lookup() #6499
Conversation
2f208b0
to
271623e
Compare
Great, would it be much trouble to break the work into several commits? For example, I envisioned that moving the BooleanField stuff to the admin listfilter could stand on its own. I think it could make review easier as well as bisecting possible regressions or untested behaviors that might change with a big patch like this. f you feel there's no value in this, I won't insist. I believe we need a deprecation path for custom fields that use |
I admit the boolean filter stuff could stand on its own, but apart from that, it's a bit difficult to split because changes are closely related. For the deprecation path, if a custom field is using |
Okay, let's see what the ORM guys think. I also asked on django-developers if anyone who implements these methods could test this PR. |
The reason get_prep_lookup() was left as it is was support for old-style lookups. +1 to the change, much cleaner this way. |
271623e
to
c22ddcb
Compare
Should we add anything about the new logic to |
Hmmh, what if a field requires special preparation for one of the built-in lookups? I guess in this rare case one could add a subclass of the built-in lookup with custom preparation code, and register that as an overriding lookup for the field. Something like:
Do we need to document something like this as an upgrade path? |
Sounds good to me. |
@@ -18,5 +18,5 @@ def get_prep_value(self, value): | |||
return super(NoopField, self).get_prep_value(value) | |||
|
|||
field = NoopField() | |||
field.get_db_prep_lookup('exact', 'TEST', connection=connection, prepared=False) | |||
field.get_prep_value('TEST') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test is obsolete now.
I've finished removing most of the internal usage of |
The plan looks good. |
c22ddcb
to
75b6230
Compare
Tim, feel free to take the patch to complete/polish it. |
Hopefully claudep#5 takes care of the remaining needs. |
9f6e4c9
to
50aeb2b
Compare
Thanks Tim Graham for completing the initial patch.
50aeb2b
to
388bb5b
Compare
@claudep and @akaariai , I apologize for commenting on an old PR, but I'm finally working on migrating from 1.9 to 1.10 now. Do I understand correctly that lookups will call custom fields' get_prep_value() methods now instead of get_prep_lookup()? There was no conversation on the issue, the release notes seem to assume a different use case than mine, and I can't find any "removed in Django 1.10" or similar notes in the documentation on this. My uses are: Custom field 1: get_prep_lookup() just calls value.to_db_value() if the value is an object of the type the field is meant to store (as opposed to a string, etc.), then calls super. Custom field 2: get_prep_lookup() grabs the attribute that we actually want to serialize (if present on the value, which it would be if the value is an object of the type the field is meant to store as opposed to a string, etc.), then calls super. Do I need to do anything aside from delete the get_prep_lookup()s? In both of my cases, get_prep_value() would produce the same result. Apologies if this is the wrong place to ask this question or if I missed existing documentation on this. |
It's not really the best place to ask. You could use our support channels. Also, Django is open source so you can inspect how it works. :-) |
I'll look at those support channels, thanks. Inspecting the code was how I got as far as thinking they call get_prep_value() now, but I wasn't sure if I was looking at the right stuff. |
https://code.djangoproject.com/ticket/22936