Django 3.1: AttributeError: module 'django.db.models.fields' has no attribute 'FieldDoesNotExist' with annotation
danjac opened this issue · 3 comments
danjac commented
This is raised in io.py when using an annotation:
def to_fields(qs, fieldnames):
for fieldname in fieldnames:
model = qs.model
for fieldname_part in fieldname.split('__'):
try:
field = model._meta.get_field(fieldname_part)
> except django.db.models.fields.FieldDoesNotExist:
E AttributeError: module 'django.db.models.fields' has no attribute 'FieldDoesNotExist'
/usr/local/lib/python3.8/site-packages/django_pandas/io.py:12: AttributeError
This should be changed to django.core.exceptions.FieldDoesNotExist as this is removed in Django 3.1
thomasjbradley commented
I would love this fixed also! But it seems like that fix means django-pandas
wouldn’t be backwards compatible to Django>=1.4.5
then (at least from my quick digging around).
It’s a big problem because I cannot reference annotated fields in the fieldnames
argument in Django/3.1.
danjac commented
It should be possible to check with an ImportError to know which version FieldDoesNotExist to use, if backward compatibility is needed.
mateoreyes commented
from django.core.exceptions import FieldDoesNotExist
def to_fields(qs, fieldnames):
for fieldname in fieldnames:
model = qs.model
for fieldname_part in fieldname.split('__'):
try:
field = model._meta.get_field(fieldname_part)
except FieldDoesNotExist: