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

Add notes to docs about get_metadata() vs. get_raw_metadata() #1398

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

jwodder
Copy link
Member

@jwodder jwodder commented Jan 31, 2024

Closes #1363.

@jwodder jwodder added the patch Increment the patch version when merged label Jan 31, 2024
Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (96c3953) 88.51% compared to head (9e521e3) 88.59%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1398      +/-   ##
==========================================
+ Coverage   88.51%   88.59%   +0.07%     
==========================================
  Files          77       77              
  Lines       10492    10492              
==========================================
+ Hits         9287     9295       +8     
+ Misses       1205     1197       -8     
Flag Coverage Δ
unittests 88.59% <ø> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

try:
return models.Dandiset.parse_obj(self.get_raw_metadata())
except ValidationError as e:
raise ValueError(
Copy link
Member

Choose a reason for hiding this comment

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

IMHO we should not adapt into another type of exception here -- ValidationError has .errors() etc...

could you please subclass it locally with __init__ to copy over errors and model and adjust its __str__ to get that note ?

Copy link
Member Author

Choose a reason for hiding this comment

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

While subclassing looks like it would work in Pydantic 1.x, it won't work in 2.x, as there ValidationError is implemented in Rust, and the only public Python method I see for creating a ValidationError is a static method that can only ever return a ValidationError, not a custom subclass.

Copy link
Member

Choose a reason for hiding this comment

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

oh! I have missed **v1** in that pydantic/v1/error_wrappers.py path... what could possibly go wrong by mixing Python and Rust? I guess we are yet to see and for now just enjoy public classes/interfaces like

In [5]: ValidationError?
Init signature: ValidationError(self, /, *args, **kwargs)
Docstring:      Inappropriate argument value (of correct type).
File:           ~/venvs/dev3.11/lib/python3.11/site-packages/pydantic_core/_pydantic_core.cpython-311-x86_64-linux-gnu.so
Type:           type
Subclasses:   

which cannot even

In [6]: ValidationError()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 ValidationError()

TypeError: No constructor defined

heh... I really do not see then a way we could improve UX/DX here then... we should not issue warnings etc. I guess let's just leave the note in the doc string and be done with it.

@jwodder jwodder changed the title Add notes to error messages & docs about get_metadata() vs. get_raw_metadata() Add notes to docs about get_metadata() vs. get_raw_metadata() Feb 1, 2024
@jwodder jwodder added documentation Changes only affect the documentation and removed patch Increment the patch version when merged labels Feb 1, 2024
@jwodder jwodder requested a review from yarikoptic February 1, 2024 17:33
@yarikoptic
Copy link
Member

Thank you @jwodder

@yarikoptic yarikoptic merged commit 98f5cf7 into master Feb 1, 2024
28 checks passed
@yarikoptic yarikoptic deleted the gh-1363 branch February 1, 2024 19:38
@yarikoptic yarikoptic added the DX Developer eXperience label Feb 1, 2024
Copy link

github-actions bot commented Feb 2, 2024

🚀 PR was released in 0.59.1 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Changes only affect the documentation DX Developer eXperience released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] .get_metadata() from embargoed dandiset
2 participants