KarrLab / obj_tables

Tools for creating and reusing high-quality spreadsheets
https://objtables.org
MIT License
8 stars 2 forks source link

Requirement that Observables (and other Models, I presume) have a unique expression generates obscure error msg #105

Closed artgoldberg closed 4 years ago

artgoldberg commented 4 years ago
ValueError: Attribute 'Observable:observable_1' of 'ObservableExpression:species_1[comp]' must be `None`
jonrkarr commented 4 years ago

I have made the error message more informative.

Essentially, this error is the manifestation of the principle of least astonishment.

This error is related to OneToOneAttributes. Their values cannot be directly changed to other non-None values because doing so could cause opaque side effects to the reverse relationship of the related object, which could confuse users because its not something they would likely anticipate. To change their value, the value should first be set to None. Then the value can be changed to another non-None value. wc_lang/tests/test_core.py:test_non_unique_error_message and obj_tables/tests/test_core.py:test_onetooneattribute illustrate how this is intended to work.

Strictly speaking, its not necessary to throw an error in this scenario. Another potential way to navigate this issue would be to provide another method with a name like safe_set_value. The downside would be that most users would likely use the default method when they should generally use the safe method.