@@ -122,14 +122,7 @@ def _get_model_dict(model: Model) -> dict:
122122 model_json = model_json .get ("fields" )
123123 model_json ["pk" ] = model_pk
124124
125- exclude_field_related_names = getattr (
126- model , "__unicorn__exclude_field_related_names" , []
127- )
128-
129125 for related_name in _get_many_to_many_field_related_names (model ):
130- if related_name in exclude_field_related_names :
131- continue
132-
133126 pks = []
134127
135128 try :
@@ -282,58 +275,6 @@ def _exclude_field_attributes(
282275 del dict_data [field_name ][field_attr ]
283276
284277
285- def _handle_many_to_many_excluded_field_attributes (
286- data : Dict , exclude_field_attributes : Optional [Tuple [str ]]
287- ) -> Optional [Tuple [str ]]:
288- """
289- Explicitly handle excluding many-to-many fields on models with a semi-hacky private
290- `__unicorn__exclude_field_related_names attribute that gets used later in `_get_model_json`.
291- Since the many-to-many field won't be serialized, remove it from the list so it won't
292- be tried to be removed in `_exclude_field_attributes`.
293- """
294-
295- if exclude_field_attributes :
296- many_to_many_field_attributes = set ()
297-
298- for field_attributes in exclude_field_attributes :
299- if "." not in field_attributes :
300- continue
301-
302- (field_attribute , exclude_field_related_name , * _ ) = field_attributes .split (
303- "."
304- )
305-
306- for key in data .keys ():
307- if isinstance (data [key ], Model ) and key == field_attribute :
308- model = data [key ]
309-
310- many_to_many_related_names = _get_many_to_many_field_related_names (
311- model
312- )
313-
314- if exclude_field_related_name in many_to_many_related_names :
315- if hasattr (model , "__unicorn__exclude_field_related_names" ):
316- model .__unicorn__exclude_field_related_names .append (
317- exclude_field_related_name
318- )
319- else :
320- setattr (
321- model ,
322- "__unicorn__exclude_field_related_names" ,
323- [exclude_field_related_name ],
324- )
325-
326- many_to_many_field_attributes .add (field_attributes )
327- break
328-
329- # Convert list to tuple again so it's hashable for `lru_cache`
330- exclude_field_attributes = tuple (
331- set (exclude_field_attributes ) - many_to_many_field_attributes
332- )
333-
334- return exclude_field_attributes
335-
336-
337278def dumps (
338279 data : Dict , fix_floats : bool = True , exclude_field_attributes : Tuple [str ] = None
339280) -> str :
@@ -356,10 +297,6 @@ def dumps(
356297 exclude_field_attributes
357298 ), "exclude_field_attributes type needs to be a sequence"
358299
359- exclude_field_attributes = _handle_many_to_many_excluded_field_attributes (
360- data , exclude_field_attributes
361- )
362-
363300 serialized_data = orjson .dumps (data , default = _json_serializer )
364301
365302 if fix_floats :
0 commit comments