Skip to content

Commit

Permalink
fix: fix django model serializable_value not catching for WrongManage…
Browse files Browse the repository at this point in the history
…r exception
  • Loading branch information
bnznamco committed Oct 6, 2022
1 parent 23095fb commit 34abd77
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions hvad/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db.models.signals import class_prepared
from django.utils.translation import get_language
from hvad.descriptors import LanguageCodeAttribute, TranslatedAttribute
from hvad.exceptions import WrongManager
from hvad.fields import SingleTranslationObject, MasterKey
from hvad.manager import TranslationManager
from hvad.settings import hvad_settings
Expand Down Expand Up @@ -201,6 +202,13 @@ class Meta:
abstract = True
base_manager_name = '_plain_manager'

def serializable_value(self, field_name):
try:
field = self._meta.get_field(field_name)
except (FieldDoesNotExist, WrongManager):
return getattr(self, field_name)
return getattr(self, field.attname)

def __init__(self, *args, **kwargs):
# Split arguments into shared/translatd
veto_names = ('pk', 'master', 'master_id', self._meta.translations_model._meta.pk.name)
Expand Down

0 comments on commit 34abd77

Please sign in to comment.