You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This pull request improves the serialization and deserialization of schema.org-style @id, @type, and @context fields in entity models, ensuring that these fields are handled consistently and only included when defined in the model. It also adds comprehensive tests to verify the correct behavior for models with and without an at_id field.
Enhancements to schema field serialization/deserialization:
Refactored the handling of @type, @context, and @id fields in _schema_mixin.py by introducing helper functions _deserialize_at_field and _serialize_at_field, ensuring these fields are only set or serialized if defined in the model or if extra fields are allowed. This prevents unintended attributes from being added to models.
Updated validate_schema_model and serialize_schema_model to use the new helper functions, improving maintainability and correctness of schema field processing.
Model updates:
Added an optional at_id field to the ClientCitation model to support deserialization and serialization of the @id property.
Testing improvements:
Added tests to verify that models without an at_id field ignore the @id property during (de)serialization, and that models with at_id handle it correctly. Also added tests for nested deserialization scenarios (e.g., Activity containing a ClientCitation).
Included missing import of Activity in the serialization test module to support new tests.
This drops schema aliases for programmatically supplied extras. Entity allows extra fields and uses this serializer, so Entity(type="custom", at_id="schema-id").model_dump(by_alias=True) previously included "@id" but now emits only the ordinary atId extra. The validator explicitly treats schema fields as valid when extras are allowed, so serialization should retain that same path rather than returning solely because the field is not declared.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the serialization and deserialization of schema.org-style
@id,@type, and@contextfields in entity models, ensuring that these fields are handled consistently and only included when defined in the model. It also adds comprehensive tests to verify the correct behavior for models with and without anat_idfield.Enhancements to schema field serialization/deserialization:
@type,@context, and@idfields in_schema_mixin.pyby introducing helper functions_deserialize_at_fieldand_serialize_at_field, ensuring these fields are only set or serialized if defined in the model or if extra fields are allowed. This prevents unintended attributes from being added to models.validate_schema_modelandserialize_schema_modelto use the new helper functions, improving maintainability and correctness of schema field processing.Model updates:
at_idfield to theClientCitationmodel to support deserialization and serialization of the@idproperty.Testing improvements:
at_idfield ignore the@idproperty during (de)serialization, and that models withat_idhandle it correctly. Also added tests for nested deserialization scenarios (e.g.,Activitycontaining aClientCitation).Activityin the serialization test module to support new tests.