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

🩹 Fix schema generation by making private attributes private #1382

Merged
merged 2 commits into from
Oct 22, 2023

Conversation

s-weigand
Copy link
Member

@s-weigand s-weigand commented Oct 21, 2023

With pydantic 2 we had crashes when calling .model_json_schema() e.g.

from glotaran.project import Scheme

Scheme.model_json_schema()

The main reason for this was pydatic failure to serialize data_model_type to json since the value is a class.

This can all be prevented by making internal only fields "private" (leading _) so they get excluded from the schema since we don't want users to put values for them anyway.

As @joernweissenborn noted properly typing the fields with ClassVar those variables will also not be considered for the schema.

@github-actions
Copy link
Contributor

Binder 👈 Launch a binder notebook on branch s-weigand/pyglotaran/fix-schema-generation

@s-weigand
Copy link
Member Author

This PR is a draft since it depends on #1381

@codecov
Copy link

codecov bot commented Oct 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
glotaran/builtin/elements/baseline/element.py 90.0% <100.0%> (+0.5%) ⬆️
glotaran/builtin/elements/clp_guide/element.py 100.0% <100.0%> (ø)
...aran/builtin/elements/coherent_artifact/element.py 77.5% <100.0%> (+0.2%) ⬆️
...ran/builtin/elements/damped_oscillation/element.py 94.3% <100.0%> (+<0.1%) ⬆️
glotaran/builtin/elements/kinetic/element.py 89.8% <100.0%> (+0.1%) ⬆️
glotaran/builtin/elements/spectral/element.py 85.0% <100.0%> (+0.3%) ⬆️
glotaran/model/data_model.py 87.5% <ø> (ø)
glotaran/model/element.py 96.6% <ø> (ø)

📢 Thoughts on this report? Let us know!.

@jsnel jsnel force-pushed the fix-schema-generation branch from 691d842 to f6cda8c Compare October 22, 2023 06:20
@jsnel
Copy link
Member

jsnel commented Oct 22, 2023

This PR is a draft since it depends on #1381

That PR has been merged, so promoting this PR.

@jsnel jsnel marked this pull request as ready for review October 22, 2023 06:25
@jsnel jsnel requested review from jsnel, joernweissenborn and a team as code owners October 22, 2023 06:25
Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

LGTM. Examples ran successfully.

@s-weigand s-weigand force-pushed the fix-schema-generation branch from f6cda8c to 985e691 Compare October 22, 2023 13:19
Copy link
Member

@joernweissenborn joernweissenborn left a comment

Choose a reason for hiding this comment

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

Lgtm, but in the long run we should put these things into a ElementConfig class.

@s-weigand s-weigand force-pushed the fix-schema-generation branch from 985e691 to a5c6fa8 Compare October 22, 2023 15:13
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@s-weigand s-weigand merged commit 719a2d5 into glotaran:staging Oct 22, 2023
@s-weigand s-weigand deleted the fix-schema-generation branch October 22, 2023 17:59
jsnel pushed a commit to jsnel/pyglotaran that referenced this pull request Jun 2, 2024
…n#1382)

* 🩹 Fix schema generation by making private attributes private

* 🧹 Rename back and properly type ClassVar fields
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.

3 participants