Commit 8ad2db23 authored by Yannick DAYER's avatar Yannick DAYER

Prevent triggering of delayed_attributes at copy.

parent 0b743b85
Pipeline #50745 failed with stage
in 3 minutes and 9 seconds
......@@ -15,10 +15,15 @@ SAMPLE_DATA_ATTRS = ("data", "samples")
def _copy_attributes(sample, parent, kwargs):
"""Copies attributes from a dictionary to self."""
if parent is not None:
if getattr(parent, "_delayed_attributes") is not None:
setattr(sample, "_delayed_attributes", parent._delayed_attributes)
for key in parent.__dict__:
if key.startswith("_") or key in SAMPLE_DATA_ATTRS:
# Prevent the assignment of delayed attributes when copying
if getattr(parent, "_delayed_attributes") is not None and key in getattr(parent, "_delayed_attributes"):
setattr(sample, key, None)
setattr(sample, key, getattr(parent, key))
for key, value in kwargs.items():
......@@ -119,11 +124,16 @@ class DelayedSample(_ReprMixin):
def __init__(self, load, parent=None, delayed_attributes=None, **kwargs):
self.__running_init__ = True
self._delayed_attributes = delayed_attributes
# create the delayed attributes but leave the their values as None for now.
self._delayed_attributes = None
# create the delayed attributes but leave their values as None for now.
if delayed_attributes is not None:
kwargs.update({k: None for k in delayed_attributes})
# Inherit attributes from parent, without calling delayed_attributes
_copy_attributes(self, parent, kwargs)
if self._delayed_attributes is not None and delayed_attributes is not None:
self._delayed_attributes = delayed_attributes
self._load = load
del self.__running_init__
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment