CustomCheck does not respect enabled keyword
tuchandra opened this issue · 3 comments
Hello! I heard about bulwark at Chipy a few weeks back and it seemed awesome (great talk!). I just got around to trying it out on a personal project of mine.
It looks like a CustomCheck does not respect the enabled
keyword. To my knowledge, the following should run fine, but fails when run top-to-bottom.
import bulwark.checks as ck
import bulwark.decorators as dc
def this_fails(df):
assert False
return df
@dc.CustomCheck(this_fails, enabled=False)
def do_thing():
return 12
do_thing()
raises the stack trace
In [35]: import bulwark.checks as ck
...: import bulwark.decorators as dc
...:
...: def this_fails(df):
...: assert False
...: return df
...:
...: @dc.CustomCheck(this_fails, enabled=False)
...: def do_thing():
...: return 12
...:
In [36]: do_thing()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-36-3911ada705c2> in <module>
----> 1 do_thing()
~/miniconda3/envs/scooter/lib/python3.7/site-packages/bulwark/decorators.py in wrapper(*operation_args, **operation_kwargs)
60 def wrapper(*operation_args, **operation_kwargs):
61 df = operation_func(*operation_args, **operation_kwargs)
---> 62 ck.custom_check(check_func, df, *args, **kwargs)
63 return df
64 return wrapper
~/miniconda3/envs/scooter/lib/python3.7/site-packages/bulwark/checks.py in custom_check(check_func, df, *args, **kwargs)
521 """
522 try:
--> 523 check_func(df, *args, **kwargs)
524 except AssertionError as e:
525 msg = "{} is not true.".format(check_func.__name__)
TypeError: this_fails() got an unexpected keyword argument 'enabled'
It looks like the code for custom_check
(here) doesn't fit into BaseDecorator based on the TODO, which is what uses self.enabled
. But there's a lot of magic going on here, so I'm not totally sure of the cause.
Thanks for this report. Looks like I just forgot to add support for this. Right now every arg/kwarg is just being passed to the check function. Mimicking BaseDecorator's enabled check is probably the easiest way to add this capability. I'll try and put something together ASAP.
I believe I've fixed the issue and a couple potential others with CustomCheck
decorator. I'm going to take a break, so I can double-check with fresh eyes before merging, but should be merged tonight.
Cheers, thanks for the prompt response and fix! I appreciate it a lot.