diff --git a/reactivated/serialization/__init__.py b/reactivated/serialization/__init__.py index 595e7295a..42772be08 100644 --- a/reactivated/serialization/__init__.py +++ b/reactivated/serialization/__init__.py @@ -340,6 +340,8 @@ def get_serialized_value( else class_or_instance() ) + name = f"{value.__class__.__module__}.{value.__class__.__qualname__}" + for field in value: if ( isinstance(field.field, django_forms.ModelChoiceField) @@ -347,6 +349,14 @@ def get_serialized_value( ): field.field.queryset = field.field.queryset.none() + if ( + callable(field.field.initial) + and schema.definitions.get("is_static_context") is True # type: ignore[comparison-overlap] + ): + assert ( + False + ), f"Callables are not supported in initial/default values for field {field.name} in form {name}" + form = value context = form.get_context() # type: ignore[attr-defined] @@ -362,9 +372,7 @@ def get_serialized_value( value.fields = {**hidden_fields, **visible_fields} serialized = serialize(value, schema, suppress_custom_serializer=True) - serialized[ - "name" - ] = f"{value.__class__.__module__}.{value.__class__.__qualname__}" + serialized["name"] = name serialized["prefix"] = form.prefix or "" serialized["iterator"] = list(hidden_fields.keys()) + list( visible_fields.keys()