DAL.lazy_define_table of a Table with a self-reference (foreign key to itself) will not work with default validators, and crash with an AttributeError.
The chain of effect:
- Field.bind tries to update the default validator - which has not been set before because the table is not yet defined
- get_default_validator tries to resolve the referenced table through Field.referenced_table/field
- Field.referenced_field crashes with an AttributeError when attempting to access self._db[tablename], which should not be possible given that it has just passed the test whether tablename is in self._db
Workarounds:
An explicit requires parameter on the self-reference side-steps the problem, as does setting lazy_tables=False on the DAL instance.
Analysis:
It is not immediately obvious why Field.referenced_field would pass the check whether tablename is in self._db, and then crash in the very next line in the attempt to access the exact same key. Maybe I am missing a layer of recursion here?
DAL.lazy_define_tableof a Table with a self-reference (foreign key to itself) will not work with default validators, and crash with an AttributeError.The chain of effect:
Workarounds:
An explicit
requiresparameter on the self-reference side-steps the problem, as does settinglazy_tables=Falseon the DAL instance.Analysis:
It is not immediately obvious why
Field.referenced_fieldwould pass the check whethertablenameis inself._db, and then crash in the very next line in the attempt to access the exact same key. Maybe I am missing a layer of recursion here?