RecursionError при доступе к нулевому десятичному полю в Django - PullRequest
0 голосов
/ 10 мая 2018

У меня есть модель в Django 1.11.2, которая имеет DecimalField.Поле обнуляется.При доступе к полю я по какой-то причине получаю ошибку рекурсии.

ipdb> student.current_longitude
*** RecursionError: maximum recursion depth exceeded while getting the str of an object
ipdb>

Может ли это быть как-то связано с сериализацией нулевого значения в DecimalField?Что здесь происходит?

ipdb> type(student.current_longitude)
*** RecursionError: maximum recursion depth exceeded while getting the str of an object
ipdb>

Определение модели

current_longitude = models.DecimalField(null=True, blank=True, decimal_places=13, max_digits=16)
current_latitude = models.DecimalField(null=True, blank=True, decimal_places=13, max_digits=16)

ОБНОВЛЕНИЕ

Есть миксин с __setattr__, который выбрасывает исключение:

def __setattr__(self, key, value):

    if key in ('updated_at',):
        pass

    elif getattr(self, '_initiated', False) and key not in getattr(self, '_non_model_fields', set()):
        try:
            field = self._meta.get_field(key)
        except FieldDoesNotExist:
            self._non_model_fields.add(key)
        else:
            # Foreignkeys may show up twice once as _id and once as the object
            # and for serialization and consistency purposes we only want the _id property
            # so we detect if the field is a FK and it's the FK not ending in _id and exclude it.
            # Also GeopositionField is ignoring because this field raises recursion depth via this mixin
            if isinstance(field, ForeignKey) and key[-3:] != '_id' or isinstance(field, GeopositionField):
                self._non_model_fields.add(key)
            else:
                old_value = getattr(self, key)
                if old_value != value:
                    self._dirty_fields[key] = old_value

В этой строке выдается исключение old_value = getattr(self, key).Почему getattr() вызывает сеттер?

...