MongoEngine / MongoEngine/mongoengine
Feature request: Prevent to set "non-fields" attribute after Document gets initialized
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Hi,
We have a decent code base that uses mongoengine and a few times, we had the issues when renaming attributes that some places weren't updated in the code and that it was silently "failing" (it was setting an attribute that is no longer a field and is simply ignored silently when .save()). In our code base we are never setting attribute after Document gets initialized.
The following is what we want to achieve:
class Person(Document):
name = StringField()
p = Person(last_name='whatever')
p.a_new_attr = 3 # raises AttributeError (or on the .save)
We can achieve this by simply overriding setattr but I was wondering if this is a behavior that you would be interested in having in mongoengine as an optional argument in meta for instance? Please let me know your thoughts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by locating Document attribute assignment and save behavior, then examine how an optional meta setting could govern non-field attributes after initialization. Done means the requested example reliably raises AttributeError, with the chosen configuration and behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100