Project

Profile

Help

Issue #8396

closed

AttributeError: 'NoneType' object has no attribute 'get_host'

Added by ipanova@redhat.com over 3 years ago. Updated over 3 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 95
Quarter:

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

Related to Pulp - Issue #8190: AttributeError: 'NoneType' object has no attribute 'query_params'CLOSED - DUPLICATElmjachkyActions
Actions #1

Updated by ipanova@redhat.com over 3 years ago

this issue is whether related or a dup https://pulp.plan.io/issues/8190. Needs investigation.

Actions #2

Updated by fao89 over 3 years ago

  • Triaged changed from No to Yes
Actions #3

Updated by lmjachky over 3 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to lmjachky
  • Sprint set to Sprint 93
Actions #4

Updated by lmjachky over 3 years ago

  • Related to Issue #8190: AttributeError: 'NoneType' object has no attribute 'query_params' added
Actions #5

Updated by lmjachky over 3 years ago

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).

Actions #6

Updated by pulpbot over 3 years ago

  • Status changed from ASSIGNED to POST
Actions #7

Updated by rchan over 3 years ago

  • Sprint changed from Sprint 93 to Sprint 94
Actions #8

Updated by rchan over 3 years ago

  • Sprint changed from Sprint 94 to Sprint 95

Added by Lubos Mjachky over 3 years ago

Revision d7a7a3b2 | View on GitHub

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

Actions #9

Updated by Anonymous over 3 years ago

  • Status changed from POST to MODIFIED
Actions #10

Updated by dalley over 3 years ago

  • Sprint/Milestone set to 3.13.0
Actions #11

Updated by pulpbot over 3 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF