select_related(depth=0) should be a no-op
|Reported by:||Roman Odaisky||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The documentation does not define any behavior for queryset.select_related(depth=0). The implementation treats that as if the depth parameter were not set at all, selecting all related objects.
I propose having queryset.select_related(depth=0) return the same queryset, unaltered. That does not break documented behavior because it is not documented in the first place.
The reason is uniformity. Suppose I want to test how select_related affects performance. I add a constant and add select_related(depth=SELECT_RELATED_DEPTH) in several places. I want to benchmark the application with different values, but the existing implementation of select_related does not allow me to set a value that would disable select_related altogether.
The patch is very simple, attaching.
Change History (11)
comment:3 Changed 8 years ago by
|Patch needs improvement:||set|
comment:4 Changed 7 years ago by
|Patch needs improvement:||unset|