Skip to content

Default validators break self-references #756

@nursix

Description

@nursix

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions