tortoise / tortoise/tortoise-orm

Cloned models do not have required attributes

Open
#824 2 comments 0 reactions 0 assignees View on GitHub

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

  1. Initialize a model, such as model = Item(name="Test")
  2. Clone it, such as cloned = model.clone()
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.