Skip to content

Commit

Permalink
add boolean field, move process_signature call from __init__ to valid…
Browse files Browse the repository at this point in the history
…ate so foreignkeys dont validate related sweepers on definition, fix typo
  • Loading branch information
sixpearls committed Jan 16, 2019
1 parent 59fb26f commit 9e8128c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sweepable.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
type_to_field = {
int: peewee.IntegerField,
float: peewee.FloatField,
bool: peewee.BooleanField,
}

try:
Expand Down Expand Up @@ -329,8 +330,6 @@ def __init__(self, function, output_fields, auto_migrate=False,
self.create_table = create_table
self.delete_files = delete_files

self.process_signature()

# TODO: is there a reason not to validate here by default? see
# discussion about queue database above

Expand All @@ -346,7 +345,6 @@ def process_signature(self):
param_default.default is not None):
self.input_fields[param] = param_default
elif isinstance(param_default, sweeper):
# TODO: This causes the FK model to validate; could we defer?
self.input_fields[param] = peewee.ForeignKeyField(
param_default.model)
elif type(param_default) in type_to_field:
Expand Down Expand Up @@ -399,6 +397,7 @@ def migrate(self, add_fields, drop_fields):
)

def validate(self, do_migrate=False):
self.process_signature()
arg_fields = {**self.input_fields, **self.output_fields}
arg_fields['__repr__'] = SweepableModel.__repr__
# TODO: this is a bug peewee, __repr__ can't be inherited.
Expand Down Expand Up @@ -431,7 +430,7 @@ def validate(self, do_migrate=False):

if not (self.auto_migrate or do_migrate) and \
(drop_fields or add_fields):
error_string = self.model.__model_str__() + "current code " +\
error_string = self.model.__model_str__() + " current code " +\
"specification does not match database. You may need to" +\
" migrate the database."
if drop_fields:
Expand Down

0 comments on commit 9e8128c

Please sign in to comment.