Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #31863 -- Prevented mutating model state by copies of model instances. #13281

Merged
merged 1 commit into from
Aug 12, 2020

Conversation

GertBurger
Copy link
Contributor

ticket-31863
Discussion at https://groups.google.com/g/django-developers/c/QMhVPIqVVP4/m/kcvbnCn0AwAJ

Django 2.0 introduced a fields cache for model fields which ends up being copied during a model instance copy. This results in changes to the new model instance unexpectedly affecting the original model instance (last 2 asserts in test fails). In Django 1.11 and earlier the behavior was as expected when using copy.

This is my first PR to the Django project so please point out any thing I missed whilst reading the contributor guidelines. CLA was submitted last night.

django/db/models/base.py Outdated Show resolved Hide resolved
@felixxm felixxm changed the title Fixed #31863: Reset model fields cache on copy Fixed #31863 -- Prevented mutating model state by copies of model instances. Aug 7, 2020
Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GertBurger Thanks for this patch 👍 I left comments.

django/db/models/base.py Outdated Show resolved Hide resolved
tests/model_regress/tests.py Outdated Show resolved Hide resolved
tests/model_regress/tests.py Outdated Show resolved Hide resolved
tests/model_regress/tests.py Outdated Show resolved Hide resolved
tests/model_regress/tests.py Outdated Show resolved Hide resolved
tests/model_regress/tests.py Outdated Show resolved Hide resolved
tests/model_regress/tests.py Outdated Show resolved Hide resolved
@GertBurger GertBurger force-pushed the #31863-model-field-cache-copy branch from f04ec81 to a019411 Compare August 9, 2020 13:17
django/db/models/base.py Outdated Show resolved Hide resolved
@GertBurger GertBurger force-pushed the #31863-model-field-cache-copy branch 2 times, most recently from 368cd37 to 6f9635c Compare August 10, 2020 09:49
@felixxm felixxm self-assigned this Aug 11, 2020
@felixxm felixxm force-pushed the #31863-model-field-cache-copy branch from 6f9635c to 94ea79b Compare August 12, 2020 10:49
@felixxm
Copy link
Member

felixxm commented Aug 12, 2020

@GertBurger Thanks 👍 Welcome aboard ⛵

@felixxm felixxm merged commit 94ea79b into django:master Aug 12, 2020
@GertBurger GertBurger deleted the #31863-model-field-cache-copy branch September 26, 2022 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants