Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As announced in #158, this PR adds
Table.remove_data()
(and fixes sometype: ignore
comments).Two things to note here, mainly:
table.data = ...
triggers the data validation, but when we're removing data, we don't actually need to validate the data remaining in thetable
as that has been validated when we added it previously.Unfortunately, sqlalchemy's docs don't hint at any possibility to skip the validation check when using
@validates
as we do. They do state that removals from a collection generally don't trigger this, but we don't have a proper collection, just adict
data attribute. So this would be a benefit of normalizing our data model further, sincetable.data
would then be a proper collection.In the meantime, though, I was wondering whether we need
@validates
at all. We do need to validate data, but we don't exposetable.data
in the DB layer, so there's no chance of a user accidentally setting this to some invalid data. Thus, I'm not sure we benefit all that much from the@validates
functionality of automatically checking.data
each time it is set; we could simply make sure thatadd_data()
always calls our validation function manually -- and conversely, thatremove_data()
never does that.What do you think?
remove_data()
doesn't seem to need aself.session.commit()
, whileadd_data()
does need it to pass the tests. I'm not sure we need to worry about this, either, though, as I'm happy as long as the test work as intended.