Can't change a field in a copied embedded model that's part of a collection #228
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 97
- PR merge metrics
- No merged PRs in 30d
Description
# Bug
Given a model definition like this:
class E(EmbeddedModel):
f: int
class M(Model):
e: List[E]
model = M(e=[E(f=1)])
copy = instance.copy(deep=True)
When I call copy.e[0].f = 2
Then an `AttributeError: 'E' object has no attribute '__fields_modified__'` occurs
### Environment
- ODMantic version: 0.9.2
- MongoDB version: 5.0.9
- Pydantic infos (output of `python -c "import pydantic.utils; print(pydantic.utils.version_info())"`):
```
pydantic version: 1.9.1
pydantic compiled: True
install path: /lib/python3.10/site-packages/pydantic
python version: 3.10.4 (main, May 9 2022, 12:55:22) [GCC 9.3.0]
platform: Linux-5.4.0-73-generic-x86_64-with-glibc2.31
optional deps. installed: ['typing-extensions']
```
**Additional context**
This is a continuation of #228 .
Contributor guide
Research direction
Start by reproducing the shown deep-copy scenario with an EmbeddedModel collection, then inspect the copied embedded model when assigning to copy.e[0].f. Done means the assignment changes the copied field without raising AttributeError and the original model remains unaffected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100