Skip to content

Commit

Permalink
Fix BaseModel to always deepcopy mutable defaults on first use
Browse files Browse the repository at this point in the history
  • Loading branch information
dmach committed Feb 23, 2024
1 parent aa6ccac commit acc5491
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions osc/util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ def get(self, obj):

try:
result = obj._defaults[self.name]
if isinstance(result, (dict, list)):
# make a deepcopy to avoid problems with mutable defaults
result = copy.deepcopy(result)
obj._values[self.name] = result
if self.get_callback is not None:
result = self.get_callback(obj, result)
return result
Expand Down

0 comments on commit acc5491

Please sign in to comment.