Issue #8396
closedAttributeError: 'NoneType' object has no attribute 'get_host'
Description
The traceback is from pulp_container but the root cause likely is in pulp core. In some places in the context we send request None
[ipanova@fluffy pulpcore]$ git grep '{"request": None}'
pulpcore/app/serializers/exporter.py: exported_resource.content_object, context={"request": None}
pulpcore/app/serializers/user.py: serializer = viewset.serializer_class(obj.content_object, context={"request": None})
pulpcore/app/viewsets/user.py: serializer = GroupUserSerializer(page, context={"request": None}, many=True)
pulpcore/app/viewsets/user.py: serializer = GroupUserSerializer(user, context={"request": None})
[ipanova@fluffy pulpcore]$
(pulp) [vagrant@pulp3-source-fedora32 ~]$ http :24817/pulp/api/v3/groups/4/object_permissions/
HTTP/1.1 500 Internal Server Error
Access-Control-Expose-Headers: Correlation-ID
Connection: close
Content-Length: 27
Content-Type: text/html
Correlation-ID: 2598b579ba66489197784f4ef0c11e5d
Date: Fri, 12 Mar 2021 12:57:19 GMT
Server: gunicorn/20.0.4
Vary: Cookie
X-Frame-Options: SAMEORIGIN
<h1>Server Error (500)</h1>
(pulp) [vagrant@pulp3-source-fedora32 ~]$ pjournal
-- Logs begin at Wed 2021-03-10 13:02:42 UTC. --
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: File "/usr/local/lib/pulp/lib64/python3.8/site-packages/rest_framework/serializers.py", line 548, in data
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: ret = super().data
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: File "/usr/local/lib/pulp/lib64/python3.8/site-packages/rest_framework/serializers.py", line 246, in data
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: self._data = self.to_representation(self.instance)
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: File "/usr/local/lib/pulp/lib64/python3.8/site-packages/rest_framework/serializers.py", line 515, in to_representation
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: ret[field.field_name] = field.to_representation(attribute)
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: File "/home/vagrant/devel/pulp_container/pulp_container/app/serializers.py", line 135, in to_representation
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: return f"{request.get_host()}/{value}"
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: AttributeError: 'NoneType' object has no attribute 'get_host'
Mar 12 12:57:19 pulp3-source-fedora32.fluffy.example.com gunicorn[22822]: pulp [2598b579ba66489197784f4ef0c11e5d]: 127.0.0.1 - admin [12/Mar/2021:12:57:19 +0000] "GET /pulp/api/v3/groups/4/object_permissions/ HTTP/1.1" 500 27 "-" "HTTPie/2.4.0"
Related issues
Updated by ipanova@redhat.com almost 4 years ago
this issue is whether related or a dup https://pulp.plan.io/issues/8190. Needs investigation.
Updated by lmjachky over 3 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to lmjachky
- Sprint set to Sprint 93
Updated by lmjachky over 3 years ago
- Related to Issue #8190: AttributeError: 'NoneType' object has no attribute 'query_params' added
Updated by lmjachky over 3 years ago
ipanova@redhat.com wrote:
this issue is whether related or a dup https://pulp.plan.io/issues/8190. Needs investigation.
I am not sure whether this could be considered a duplicate or not. But, the errors are caused by the same problem.
In this case, you were trying to query the permissions that contained the reference to a distribution (container.view_containerdistribution). In issue #8190, you were probably trying to query the permissions that contained the reference to a task (core.view_task).
Updated by pulpbot over 3 years ago
- Status changed from ASSIGNED to POST
Added by Lubos Mjachky over 3 years ago
Updated by Anonymous over 3 years ago
- Status changed from POST to MODIFIED
Applied in changeset pulpcore|d7a7a3b29e1625d49e585ae5d9b3b9f5569cd121.
Updated by pulpbot over 3 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
Pass the request's context to the serializers
In pulp_container, we are relying on the request's context when retrieving the host from a URL in ContainerDistributionSerializer. Since object-level permissions are tied to specific objects, the linked error was triggered only during the serialization of ContainerDistribution objects. Similarly, when a user tried to list permissions which contained task permissions, the missing context caused CreatedResourceSerializer to raise an internal error.
As of this commit, all RBAC-related serializers can benefit from the initial request's context.
closes #8396