You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works correctly with base Django querysets and any managers that inherit from the default manager. However, with Django-modeltranslation, this fails because all of the iterable classes are incorrectly inheriting from ValuesIterable. If you are expecting to parse a dict with ValuesIterable but are given a str or list, things will break.
Minimal reproducible code:
fromitertoolsimportproductfrommodeltranslation.managerimport (
FallbackValuesIterable,
FallbackValuesListIterable,
FallbackFlatValuesListIterable,
)
fromdjango.db.models.queryimport (
ValuesIterable,
ValuesListIterable,
FlatValuesListIterable,
)
modeltrans_classes= [
FallbackValuesIterable,
FallbackValuesListIterable,
FallbackFlatValuesListIterable,
]
django_classes= [ValuesIterable, ValuesListIterable, FlatValuesListIterable]
fora, binproduct(modeltrans_classes+django_classes, django_classes):
ifaisb:
continuesubclass=issubclass(a, b)
print(f"[{'✅'ifsubclasselse'❌'}] {a.__name__} is a subclass of {b.__name__}")
[✅] FallbackValuesIterable is a subclass of ValuesIterable
[❌] FallbackValuesIterable is a subclass of ValuesListIterable
[❌] FallbackValuesIterable is a subclass of FlatValuesListIterable
[✅] FallbackValuesListIterable is a subclass of ValuesIterable
[❌] FallbackValuesListIterable is a subclass of ValuesListIterable
[❌] FallbackValuesListIterable is a subclass of FlatValuesListIterable
[✅] FallbackFlatValuesListIterable is a subclass of ValuesIterable
[❌] FallbackFlatValuesListIterable is a subclass of ValuesListIterable
[❌] FallbackFlatValuesListIterable is a subclass of FlatValuesListIterable
[❌] ValuesIterable is a subclass of ValuesListIterable
[❌] ValuesIterable is a subclass of FlatValuesListIterable
[❌] ValuesListIterable is a subclass of ValuesIterable
[❌] ValuesListIterable is a subclass of FlatValuesListIterable
[❌] FlatValuesListIterable is a subclass of ValuesIterable
[❌] FlatValuesListIterable is a subclass of ValuesListIterable
As you can see, the above Django-modeltrans iterable classes should inherit from their respective Django class (ie FallbackFlatValuesList -> FlatValuesList), but they are not.
The text was updated successfully, but these errors were encountered:
By definition, a ValuesIterable should yield dicts for each row in the queryset:
Similary, ValuesListIterable yields tuples, and FlatValuesListIterable yields single values.
Therefore, you should be able to do something like this:
This works correctly with base Django querysets and any managers that inherit from the default manager. However, with Django-modeltranslation, this fails because all of the iterable classes are incorrectly inheriting from ValuesIterable. If you are expecting to parse a dict with ValuesIterable but are given a str or list, things will break.
Minimal reproducible code:
As you can see, the above Django-modeltrans iterable classes should inherit from their respective Django class (ie FallbackFlatValuesList -> FlatValuesList), but they are not.
The text was updated successfully, but these errors were encountered: