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

model: access doesn't survive R/T #343

Open
yarikoptic opened this issue Jan 26, 2021 · 7 comments
Open

model: access doesn't survive R/T #343

yarikoptic opened this issue Jan 26, 2021 · 7 comments
Assignees

Comments

@yarikoptic
Copy link
Member

(Pdb) DandiMeta.unvalidated(identifier='0001').dict(exclude_none=True)
{'identifier': '0001', 'schemaVersion': '1.0.0-rc1', 'access': [{'status': <AccessType.Open: 'dandi:Open'>}], 'repository': 'https://dandiarchive.org/'}
(Pdb) DandiMeta.unvalidated(**json.loads(DandiMeta.unvalidated(identifier='0001').json(exclude_none=True))).dict(exclude_none=True)
{'identifier': '0001', 'schemaVersion': '1.0.0-rc1', 'access': [{'status': 'dandi:Open'}], 'repository': 'https://dandiarchive.org/'}

so you can see that it putates from [{'status': <AccessType.Open: 'dandi:Open'>}] to 'access': [{'status': 'dandi:Open'}]

@satra
Copy link
Member

satra commented Jan 26, 2021

we will likely need to hack it in our models for the time being through custom parsers for embedded types. there is an open issue around this issue (pydantic/pydantic#1409) that may soon see a PR.

@yarikoptic
Copy link
Member Author

or should we just remove them for now ? (#344) ;)

@satra
Copy link
Member

satra commented Jan 26, 2021

that's not the only place where the roundtrip will run into an issue. so removing them doesn't solve the issue.

@yarikoptic
Copy link
Member Author

yes, but it is one of them so provides partial temporal workaround which would help to proceed ATM AFAIK. Sure thing if there is an alternative route which could resolve them in short term - we could go that way too (but waiting on PR in pydantic + release might take awhile)

@satra
Copy link
Member

satra commented Jan 26, 2021

we definitely cannot wait for their PR, but we can change our models to support round tripping and exporting cleaner json. this is really about serialization and deserialization.

@satra
Copy link
Member

satra commented Jan 26, 2021

btw, i did this check at the level of the model and this seems to work. i have to check how well it works with nested models:

In [13]: AccessRequirements(status=AccessType.Open).json()
Out[13]: '{"status": "dandi:Open", "email": null, "contactPoint": null, "description": null, "embargoedUntil": null}'

In [15]: AccessRequirements(**json.loads(AccessRequirements(status=AccessType.Open).json
    ...: ()))
Out[15]: AccessRequirements(status=<AccessType.Open: 'dandi:Open'>, email=None, contactPoint=None, description=None, embargoedUntil=None)

@satra
Copy link
Member

satra commented Jan 26, 2021

also simple nesting works:

In [17]: AccessRequirements(**json.loads(AccessRequirements(status=AccessType.Open, cont
    ...: actPoint=ContactPoint(email="satra@mit.edu")).json()))
Out[17]: AccessRequirements(status=<AccessType.Open: 'dandi:Open'>, email=None,
 contactPoint=ContactPoint(email='satra@mit.edu', url=None), description=None, embargoedUntil=None)

In [18]: AccessRequirements(status=AccessType.Open, contactPoint=ContactPoint(email="sat
    ...: ra@mit.edu")).json()
Out[18]: '{"status": "dandi:Open", "email": null, "contactPoint": {"email": "satra@mit.edu", "url": null},
 "description": null, "embargoedUntil": null}'

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

No branches or pull requests

2 participants