* Properly handle FieldAttribute.default if callable
Fixes #48673
* Add changelog...
* Add integration test
* Add aliases file
(cherry picked from commit 48ffd8789f4f930e2e330ab62781c43fe57ee022)
... | ... |
@@ -366,7 +366,10 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)): |
366 | 366 |
# if this evaluated to the omit value, set the value back to |
367 | 367 |
# the default specified in the FieldAttribute and move on |
368 | 368 |
if omit_value is not None and value == omit_value: |
369 |
- setattr(self, name, attribute.default) |
|
369 |
+ if callable(attribute.default): |
|
370 |
+ setattr(self, name, attribute.default()) |
|
371 |
+ else: |
|
372 |
+ setattr(self, name, attribute.default) |
|
370 | 373 |
continue |
371 | 374 |
|
372 | 375 |
# and make sure the attribute is of the type it should be |
... | ... |
@@ -549,7 +552,10 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)): |
549 | 549 |
if name in data: |
550 | 550 |
setattr(self, name, data[name]) |
551 | 551 |
else: |
552 |
- setattr(self, name, attribute.default) |
|
552 |
+ if callable(attribute.default): |
|
553 |
+ setattr(self, name, attribute.default()) |
|
554 |
+ else: |
|
555 |
+ setattr(self, name, attribute.default) |
|
553 | 556 |
|
554 | 557 |
# restore the UUID field |
555 | 558 |
setattr(self, '_uuid', data.get('uuid')) |