MongoEngine/mongoengine

Implement lazy assignment for Reverse Delete Rules (aka the NotRegistered exception)

combscCode opened this issue · 0 comments

MongoEngine will throw a NotRegistered exception when a user tries to register a delete rule on a Document that hasn't been defined yet. This is because the delete rule is stored directly on the Document class, so attempting to access the Document through get_document throws an exception. Rather than immediately throwing an exception, MongoEngine should just store the delete rule and lazily assign it to the Document once it is defined.

Fixing this issue will allow users to define bi-directional delete rules (this can currently be done by defining delete rules at runtime, but this behavior is not documented well). It also decouples delete rules from import ordering, which created a problem for my project that uses mongoengine.