tortoise / tortoise/tortoise-orm
Cloned models do not have required attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
The model.clone() function does not copy over attributes required to save a model.
To Reproduce
- Initialize a model, such as
model = Item(name="Test") - Clone it, such as
cloned = model.clone() - Save it, with
await cloned.save()
Expected behavior
The cloned model should save.
Additional context
A short investigation shows that __reduce_ex__ does not copy over the attribute that save() uses. Pickles are exempt from this for whatever reason, but I presume a copy.copy() is also victim to this problem.
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
Start at model.clone() and reduce_ex, then trace which attribute save() requires for persistence. Check whether copy.copy() follows the same path and add or update focused coverage for cloning and saving an Item; done means the cloned model saves successfully without losing required attributes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100