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

Stop invalid components being added to model #431

Merged
merged 2 commits into from Apr 24, 2019

Conversation

Projects
None yet
3 participants
@alubbock
Copy link
Member

commented Apr 12, 2019

Currently, if one adds an invalid parameter, rule etc. that generates
an exception in __init__, (e.g. a validation error), the component
is still added to the model. In interactive mode, this is annoying, as
the model has to be re-instantiated. Example:

Model()
Parameter('a', 'invalid_value')  # raises ValueError
assert len(model.parameters) == 0  # fixed in this PR
Parameter('a', 1.0)  # should succeed, fixed in this PR

This PR fixes this situation by adding the Component to the Model
(by calling Component.__init__()) last instead of first in each
affected __init__ method.

Fix invalid component handling
Previously, if one added an invalid parameter, rule etc. that generated
an exception in `__init__`, (e.g. a validation error), the component
was still added to the model. In interactive mode, this is annoying, as
the model has to be re-instantiated. Example:

    Model()
    Parameter('a', 'invalid_value')  # raises ValueError
    assert len(model.parameters) == 0  # fixed in this PR
    Parameter('a', 1.0)  # should succeed

This PR fixes this situation by adding the Component to the Model
(by calling `Component.__init__()`) last instead of first.
@coveralls

This comment has been minimized.

Copy link

commented Apr 12, 2019

Coverage Status

Coverage increased (+0.9%) to 78.892% when pulling 4d4058b on alubbock:fix_invalid_components into 66e70a0 on pysb:master.

@jmuhlich
Copy link
Member

left a comment

Good catch, simple solution.

@alubbock alubbock merged commit 9bcb2f4 into pysb:master Apr 24, 2019

2 of 3 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.9%) to 78.892%
Details

@alubbock alubbock deleted the alubbock:fix_invalid_components branch Apr 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.