Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Refactor 'schema'/'internal' classes #962

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

mferrera
Copy link
Collaborator

@mferrera mferrera commented Jan 9, 2025

This restructures how these classes are formed and where they live. It was confusing to locate them with the model when they are really just tweaks to the model for us when exporting. This refactor tries to bring some clarity to that relationship.

It also changes some of the metadata classes to use their literal values as defaults which changed the schema.

@mferrera mferrera force-pushed the move-metadata-so-called-schema branch 2 times, most recently from 10aae83 to bfe17a5 Compare January 9, 2025 12:41
This restructures how these classes are formed and where they live. It
was confusing to locate them with the model when they are really just
tweaks to the model for us when exporting. This refactor tries to bring
some clarity to that relationship.
@mferrera mferrera force-pushed the move-metadata-so-called-schema branch from bfe17a5 to 209b8ff Compare January 9, 2025 12:45
@mferrera mferrera marked this pull request as ready for review January 9, 2025 12:50
@mferrera mferrera requested a review from tnatt January 9, 2025 12:50
@mferrera
Copy link
Collaborator Author

mferrera commented Jan 9, 2025

Trying to do some structural clean-ups before these little schema changes starting incurring a version change. Have another one or two to follow

@mferrera mferrera self-assigned this Jan 9, 2025
@mferrera mferrera requested a review from slangeveld January 9, 2025 13:38
Copy link
Collaborator

@tnatt tnatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the removal of the _model.schema it always confused me what was contained inside 😄

@@ -24,6 +38,38 @@
logger: Final = null_logger(__name__)


class JsonSchemaMetadata(BaseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought for a separate PR, could this be removed from here and used in the _model.root instead? 🙂

Right now we have a mismatch between the $schema defined in the main schema and the "exported". That would take us one step closer to removing the need for a separate model for the exported metadata, I look forward to the day we can align them fully!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can't actually, this is a bit confusing:

It's confusing because our schema is getting validated by a 'worldwide' schema (validating that it's a valid schema), while our metadata is validated by our schema

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

annoying 😩 .. and confusing yes

Comment on lines 188 to +190
# TODO: Would like to use meta.Root.model_validate() here
# but then the '$schema' field is dropped from the meta_existing
validated_metadata = schema.InternalObjectMetadata.model_validate(
meta_existing
)
validated_metadata = ObjectMetadataExport.model_validate(meta_existing)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could add the $schema to the Root model instead, we could address the TODO here

Comment on lines +51 to +61
class ObjectMetadataExport(JsonSchemaMetadata, ObjectMetadata, populate_by_name=True):
"""Wraps the schema ObjectMetadata, adjusting some values to optional for pragmatic
purposes when exporting metadata."""

# These type ignores are for making the field optional
fmu: Optional[fields.FMU] # type: ignore
access: Optional[fields.SsdlAccess] # type: ignore
masterdata: Optional[fields.Masterdata] # type: ignore
# !! Keep UnsetData first in this union
data: Union[UnsetData, data.AnyData] # type: ignore
preprocessed: Optional[bool] = Field(alias="_preprocessed", default=None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are no longer creating invalid metadata since version 2.6.0 #793. ➡️ hence we can soon drop the optional fields here: 💥 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't fully realize this... maybe we can have a chat about it

@mferrera mferrera merged commit c9329d6 into equinor:main Jan 13, 2025
16 checks passed
@mferrera mferrera deleted the move-metadata-so-called-schema branch January 13, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants