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 #22936 -- Obsoleted Field.get_prep_lookup()/get_db_prep_lookup() #6499

Merged
merged 1 commit into from
May 4, 2016

Conversation

claudep
Copy link
Member

@claudep claudep commented Apr 23, 2016

@timgraham
Copy link
Member

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

@claudep
Copy link
Member Author

claudep commented Apr 23, 2016

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 get_prep_lookup it will simply not be called any longer, and I think that this will be fine most of the time. I have no precise idea about a use case where it would fail.

@timgraham
Copy link
Member

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.

@akaariai
Copy link
Member

The reason get_prep_lookup() was left as it is was support for old-style lookups. +1 to the change, much cleaner this way.

@timgraham
Copy link
Member

Should we add anything about the new logic to docs/ref/models/lookups.txt? How about a mention in the release notes? I'll be surprised if no projects need to make some changes to adapt for this change. I tried to test with this one: https://github.com/potatolondon/djangae/blob/f8429792aea7248f3090ada910db4f82d57bf873/djangae/fields/iterable.py#L31-L49 but couldn't get that test suite easily running with Django master.

@akaariai
Copy link
Member

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:

class MyField(Field):
    ...

class MyFieldExact(Exact):
    def get_prep_lookup(self):
          return do_custom_stuff_for_myfield()

MyField.register_lookup(MyFieldExact)

Do we need to document something like this as an upgrade path?

@timgraham
Copy link
Member

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')
Copy link
Member

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.

@timgraham
Copy link
Member

I've finished removing most of the internal usage of get_db_prep_lookup() in #6493. I think that's ready for merge, then you can rebase your patch and merge it. At that point we'd be ready to tackle removal or deprecation of get_db_prep_lookup(), I think.

@claudep
Copy link
Member Author

claudep commented May 2, 2016

The plan looks good.

@claudep
Copy link
Member Author

claudep commented May 2, 2016

Tim, feel free to take the patch to complete/polish it.

@timgraham timgraham changed the title Refs #22936 -- Obsoleted Field.get_prep_lookup Fixed #22936 -- Obsoleted Field.get_prep_lookup()/get_db_prep_lookup() May 2, 2016
@timgraham
Copy link
Member

Hopefully claudep#5 takes care of the remaining needs.

Thanks Tim Graham for completing the initial patch.
@goblinJoel
Copy link

goblinJoel commented Jan 11, 2017

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

@timgraham
Copy link
Member

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

@goblinJoel
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants