Skip to content

Commit 1a1e5ec

Browse files
committed
Hack to fix list views of assignments
1 parent 83a9792 commit 1a1e5ec

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ansible_base/rbac/service_api/serializers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class ObjectIDAnsibleIDField(serializers.Field):
4343

4444
def to_representation(self, value):
4545
"The source for this field is object_id, which is ignored, use content_object instead"
46-
assignment = self.parent.instance
46+
assignment = getattr(self, "_this_assignment", None)
47+
if not assignment:
48+
return None
4749
content_object = assignment.content_object
4850
if isinstance(content_object, RemoteObject):
4951
return None
@@ -69,6 +71,11 @@ class BaseAssignmentSerializer(serializers.ModelSerializer):
6971
# TODO: use the from_service to control what we sync back to
7072
from_service = serializers.CharField(write_only=True)
7173

74+
def to_representation(self, instance):
75+
# hack to surface content_object for ObjectIDAnsibleIDField
76+
self.fields["object_ansible_id"]._this_assignment = instance
77+
return super().to_representation(instance)
78+
7279
def get_created_by_ansible_id(self, obj):
7380
return str(obj.created_by.resource.ansible_id)
7481

0 commit comments

Comments
 (0)