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

dataclass defaults are accidentally shared #140

Open
cmungall opened this issue Sep 21, 2022 · 0 comments
Open

dataclass defaults are accidentally shared #140

cmungall opened this issue Sep 21, 2022 · 0 comments
Labels
BASIN-3D bug Something isn't working

Comments

@cmungall
Copy link
Contributor

defaults with dataclasses are pretty unintuitive IMO. It's a good idea to always instantiate using default_factory, otherwise you end up with things like:

>>> from basin3d.core.models import ObservedProperty, ObservedPropertyVariable
>>> op = ObservedProperty()
>>> op.observed_property_variable.basin3d_id='x'
>>> op
ObservedProperty(datasource_variable='', observed_property_variable=ObservedPropertyVariable(basin3d_id='x', full_name='', categories=[], units=''), sampling_medium='', datasource=DataSource(id='', name='', id_prefix='', location='', credentials={}), datasource_description='')
>>> op2 = ObservedProperty()
>>> op2
ObservedProperty(datasource_variable='', observed_property_variable=ObservedPropertyVariable(basin3d_id='x', full_name='', categories=[], units=''), sampling_medium='', datasource=DataSource(id='', name='', id_prefix='', location='', credentials={}), datasource_description='')
>>> op2.observed_property_variable.basin3d_id = 'y'
>>> op
ObservedProperty(datasource_variable='', observed_property_variable=ObservedPropertyVariable(basin3d_id='y', full_name='', categories=[], units=''), sampling_medium='', datasource=DataSource(id='', name='', id_prefix='', location='', credentials={}), datasource_description='')

better yet, use dataclasses or pydantic generated from linkml :-)

cmungall added a commit to cmungall/basin3d that referenced this issue Sep 21, 2022
Addresses BASIN-3D#140 but this likely needs done in other places
vchendrix pushed a commit that referenced this issue Sep 22, 2022
Addresses #140 but this likely needs done in other places
@vchendrix vchendrix added the bug Something isn't working label Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BASIN-3D bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants