GeeWee / django-auto-prefetching

Automatic prefetching for Django
MIT License
231 stars 18 forks source link

Missing `Meta` attribute error when using a `serializers.URLField` on a `models.ImageField` #74

Open Nosudrum opened 3 months ago

Nosudrum commented 3 months ago

Hello, I am currently trying to implement this package on a fairly large and complex django project, and have the following error message:

AttributeError: 'ListSerializer' object has no attribute 'Meta'

When focusing on a ViewSet with a simple serializer, I found that it disappears if I comment out the field that is defined by image_url = serializers.URLField(source="image.url"), which uses rest_framework.serializers. That image field in the model is defined with models.ImageField from django.db.models.

Can this be an issue in the package, or is there something I am missing on my end ?

Nosudrum commented 3 months ago

I've successfully solved this issue locally by moving the field type check to line 146 and making it immediately continue if the field should be ignored. This makes sure the elif line 207 is never entered. I've also added the URLField class to IGNORED_FIELD_TYPES. https://github.com/GeeWee/django-auto-prefetching/blob/a9370a6d70d21eaf583fd547d76a73bb571cf973/django_auto_prefetching/__init__.py#L155

@GeeWee up to you if this is worth a PR or not :)

GeeWee commented 3 months ago

Hey! I haven't updated (or used!) this project for a while. If you want to submit a PR with the fix and a test I'd be happy to accept it, and see if I can find time to release a new version to PyPi :)