Skip to content

Commit

Permalink
Update optimizator.py (#41)
Browse files Browse the repository at this point in the history
* Update optimizator.py

It is possible to get here from ListSerializer case and they you end up with `django.core.exceptions.FieldError: Invalid field name(s) given in select_related: ...` error

* Update __init__.py

* Update CHANGELOG.md
  • Loading branch information
michalkoza authored Sep 29, 2021
1 parent a0313a9 commit b7ab10c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.9.7] - 2021-09-29
### Changed
- Fix issue with django.core.exceptions.FieldError: Invalid field name(s) given in select_related: error.

## [0.9.6] - 2021-03-04
### Changed
- Run tests on Python 3.9.
Expand Down
2 changes: 1 addition & 1 deletion drf_tweaks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "DRF Tweaks"
__version__ = "0.9.6"
__version__ = "0.9.7"
__author__ = "Pawel Krzyzaniak"
__license__ = "MIT"
__copyright__ = "Copyright 2019 Ro"
Expand Down
5 changes: 4 additions & 1 deletion drf_tweaks/optimizator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def filter_field_name(field_name, fields_to_serialize):
if hasattr(model_class, field_name):
model_field = getattr(model_class, field_name)
if check_if_related_object(model_field):
select_related_set.add(prefix + field_name)
if is_prefetch or force_prefetch:
prefetch_related_set.add(prefix + field_name)
else:
select_related_set.add(prefix + field_name)


class AutoOptimizeMixin(object):
Expand Down

0 comments on commit b7ab10c

Please sign in to comment.