Browse code

Properly handle FieldAttribute.default if callable (#48992)

* Properly handle FieldAttribute.default if callable

Fixes #48673

* Add changelog...

* Add integration test

* Add aliases file

(cherry picked from commit 48ffd8789f4f930e2e330ab62781c43fe57ee022)

Martin Krizek authored on 2018/11/27 02:14:46
Showing 5 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+  - Fix using omit on play keywords (https://github.com/ansible/ansible/issues/48673)
... ...
@@ -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'))
556 559
new file mode 100644
... ...
@@ -0,0 +1,4 @@
0
+- hosts: localhost
1
+  serial: "{{ testing_omitted_variable | default(omit) }}"
2
+  tasks:
3
+    - debug:
0 4
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+shippable/posix/group3
0 1
new file mode 100755
... ...
@@ -0,0 +1,5 @@
0
+#!/usr/bin/env bash
1
+
2
+set -eux
3
+
4
+ansible-playbook 48673.yml -i ../../inventory -v "$@"