DateTimeField deepcopy causes error introduced in 1.2.1.
See original GitHub issueThe library moved from a shallow copy to a deep copy while moving to 1.2.1 from 1.2. This caused my project’s tests to fail when saving a model with a DateTimeField where auto_now=True
is set. Haven’t done any testing on whether this is the cause (that DateTimeField is the cause though, not sure whether that attribute is). I will try to come up with some tests the coming days as it’s very late as I post this. But what was the reason for changing the shallow copy to a deep copy? Changing the deep copy to a shallow copy resolves the issue.
This is the exact field that’s causing the issue:
last_modified = models.DateTimeField(
auto_now=True,
verbose_name=_('...'),
help_text=_('...')
)
The traceback:
File "/Users/Andreas/Development/Python/SomeProjectYay/project/app/models.py", line 218, in save
super(SomeModel, self).save(*args, **kwargs)
File "/Users/Andreas/.pyenv/versions/SomeProjectYay/lib/python3.5/site-packages/django/db/models/base.py", line 708, in save
force_update=force_update, update_fields=update_fields)
File "/Users/Andreas/.pyenv/versions/SomeProjectYay/lib/python3.5/site-packages/django/db/models/base.py", line 745, in save_base
update_fields=update_fields, raw=raw, using=using)
File "/Users/Andreas/.pyenv/versions/SomeProjectYay/lib/python3.5/site-packages/django/dispatch/dispatcher.py", line 192, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/Andreas/.pyenv/versions/SomeProjectYay/lib/python3.5/site-packages/dirtyfields/dirtyfields.py", line 124, in reset_state
new_state = instance._as_dict(check_relationship=True)
File "/Users/Andreas/.pyenv/versions/SomeProjectYay/lib/python3.5/site-packages/dirtyfields/dirtyfields.py", line 69, in _as_dict
all_field[field.name] = deepcopy(field_value)
File "/Users/Andreas/.pyenv/versions/3.5.2/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/Users/Andreas/.pyenv/versions/3.5.2/lib/python3.5/copy.py", line 291, in _reconstruct
args = deepcopy(args, memo)
File "/Users/Andreas/.pyenv/versions/3.5.2/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/Users/Andreas/.pyenv/versions/3.5.2/lib/python3.5/copy.py", line 223, in _deepcopy_tuple
y = [deepcopy(a, memo) for a in x]
File "/Users/Andreas/.pyenv/versions/3.5.2/lib/python3.5/copy.py", line 223, in <listcomp>
y = [deepcopy(a, memo) for a in x]
File "/Users/Andreas/.pyenv/versions/3.5.2/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/Users/Andreas/.pyenv/versions/3.5.2/lib/python3.5/copy.py", line 292, in _reconstruct
y = callable(*args)
TypeError: __init__() missing 2 required positional arguments: 'tz' and 'transition_type'
Python version: 3.5.2. Django version: 1.9.12.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Python: copy.deepcopy produces an error - Stack Overflow
This occurs in many instances when one accidentally tries to clone the iterator to a class. For instance, in PIL ...
Read more >marshmallow - Read the Docs
marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes. from datetime ...
Read more >Rational ClearQuest behavior changes for versions 7.1.1.x ...
Instead, a generic error message displays that is independent of the cause of the logon failure. Available starting in ClearQuest Versions 7.1.
Read more >Bug listing with status RESOLVED with resolution OBSOLETE ...
Bug :1523 - "[IDEA] Offload work by distributing trivial ebuild maintenance to users, introduce a simple stability voting system and have a core...
Read more >Databricks Runtime 7.x migration guide
Otherwise, Spark may run into errors with messages like ... own pattern strings in sql-ref-datetime-pattern.md , which is implemented via ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@romgar I’ll try to look at the issue more in detail the coming days. Feel free to ping me to remind me if it has been a while though.
@romgar I found the culprit and referenced it. Perhaps this could be prevented in the future by not deepcopying primitive types and other “protected types” as Django describes it in their serializers? https://github.com/django/django/blob/master/django/core/serializers/python.py#L44-L47