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

Validators hold state if you vlad multiple times in the same context #7

Closed
csojinb opened this issue Sep 18, 2015 · 6 comments
Closed

Comments

@csojinb
Copy link
Collaborator

csojinb commented Sep 18, 2015

It would be nice to be able to run validation from within python scripts or a shell repeatedly, without holding over state from the previous validation.

@dmcclory
Copy link

@di, what's happening is, we're initializing a Vlad object inside a function, like so: (in a python notebook)

def run_validators():
    Vlad(source=LocalFile(_output_path('plan_benefits.csv')), validators=FunValidator.validators).validate()

if there's a problem, the output looks correct the first time we call run_validators:

ERROR:vlad_logger:  SetValidator failed 4 time(s) on field: 'Subject to Cool Thing?'
ERROR:vlad_logger:    Invalid fields: ['YES', 'N/A']

if we run the same function again & again though, the error counts start increasing. (And the UniquenessValidators start to break)

ERROR:vlad_logger:  SetValidator failed 8 time(s) on field: 'Subject to Cool Thing?'
ERROR:vlad_logger:    Invalid fields: ['YES', 'N/A']
ERROR:vlad_logger:  UniqueValidator failed 40296 time(s) on field: 'Plan ID'
ERROR:vlad_logger:    Invalid fields: ['('fjsdlfjdsf', '30', '2')', '('dfklsdjfdf', '47', '2')', '('sdfjdskfjd', '28', '2')', '('sdkfjdfdk', '41', '2')'.....

@di
Copy link
Owner

di commented Sep 18, 2015

I think doing validators=copy.deepcopy(CignaPlanBenefitInfoValidator.validators) instead will solve this issue.

@dmcclory
Copy link

Yeah, I'll definitely try that out. It requires a lot of knowledge about Vladiate though.

I think this would be nicer API:

PlanInfoValidator(source=LocalFile(_output_path('plan_info.csv'))).validate()

@csojinb
Copy link
Collaborator Author

csojinb commented Sep 18, 2015

Is there any reason why you'd want to pass validators into a new Vlad with state already attached? If not, we could flush them or something in the Vlad instatiation.

@di
Copy link
Owner

di commented Sep 18, 2015

I decided this is a bug, because it is using the default validators argument (an empty dict) without checking to see if the class variable exists or not. Pushing a fix shortly.

@di
Copy link
Owner

di commented Sep 18, 2015

Is there any reason why you'd want to pass validators into a new Vlad with state already attached?

I guess if you wanted to override them for some reason, you would expect to be able to do this.

@di di closed this as completed in 035be72 Sep 18, 2015
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

3 participants