Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24946 closed New feature (wontfix)

Implement register_lookups

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

Description

I think it will be good to implement register_lookups method to more DRY and prevent something like

SomeModel.register_lookup(L1)
SomeModel.register_lookup(L2)
SomeModel.register_lookup(L2)

So we will have

SomeModel.register_lookups([L1, L2, L3])

I think django code will become somewhat clearer.

Change History (6)

comment:1 by Andriy Sokolovskiy, 9 years ago

If it is good to go, I will implement this

comment:2 by Andriy Sokolovskiy, 9 years ago

Has patch: set

Ticket is not accepted/declined yet. but anyway there is a PoC PR - https://github.com/django/django/pull/4829

comment:3 by Anssi Kääriäinen, 9 years ago

Resolution: wontfix
Status: newclosed

I'm not convinced we need this. Creating new lookups and transforms should be somewhat rare, so just writing the couple extra characters to register the lookup shouldn't be a problem when creating lookups/transforms.

I'm going to close this as wontfix. I don't feel too strongly about this, so if some other core dev does see this as an useful addition, I'm not going to object reopening this.

comment:4 by Carl Meyer, 9 years ago

FWIW, I agree that this is not needed.

comment:5 by Andriy Sokolovskiy, 9 years ago

Creating new lookups and transforms should be somewhat rare

Well, will be it rare or not, there will more and more lookups and transforms, so there will be more similar lines which is not DRY.

in reply to:  5 comment:6 by Carl Meyer, 9 years ago

Replying to coldmind:

Creating new lookups and transforms should be somewhat rare

Well, will be it rare or not, there will more and more lookups and transforms, so there will be more similar lines which is not DRY.

For what it's worth, IMO this is a mis-use of the concept of DRY. DRY means that each piece of knowledge has one and only one authoritative representation in the system. That is, it means that any given change to the system should need to be made in one location, not simultaneously in multiple different locations.

Registering multiple lookups with successive calls to register_lookup is not a violation of DRY, because each piece of information (the fact that lookup X is registered with the field, and the fact that lookup Y is registered with the field, etc.) is captured in exactly one place (the call to register_lookup). If that piece of information changes (lookup Y should no longer be registered with the field) that change needs to be made in one and only one place.

"A violation of DRY" is not the same thing as "I had to type more characters than I would have preferred to type." It's not even the same thing as "I had to type the same sequence of characters several times."

Conciseness is also of value in API design, but it's not the same issue as DRY. Its value depends a great deal on frequency of use, and it has to be weighed against other concerns, such as overall API size, confusing similarity of one method with another (leading to indecision about which method is the appropriate one to use), etc.

Note: See TracTickets for help on using tickets.
Back to Top