question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateTimeField deepcopy causes error introduced in 1.2.1.

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndreasBackxcommented, Feb 27, 2017

@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.

0reactions
AndreasBackxcommented, Jul 10, 2017

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found