AttributeError: 'NoneType' object has no attribute 'update'
jfsanchez91 opened this issue · 5 comments
Hello there,
I'm using Django Rest Framework Filters (DRFF).
I have these two models definition:
class Release(models.Model):
application = models.ForeignKey(Application, on_delete=models.CASCADE,
related_name='releases')
price = models.FloatField(default=0.0)
version_code = models.IntegerField()
class Application(models.Model):
package_name = models.CharField(max_length=144, unique=True)
description = models.TextField()
and as you can see an Application has many Releases with releated_name='releases'.
So, I have these two serializers:
class ApplicationSerializer(serializers.ModelSerializer):
releases = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class Meta:
model = Application
fields = '__all__'
class ReleaseSerializer(serializers.ModelSerializer):
class Meta:
model = Release
fields = '__all__'
these two viewsets:
class ApplicationViewSet(viewsets.ModelViewSet):
queryset = Application.objects.all()
serializer_class = ApplicationSerializer
filter_class = ApplicationFilter
class ReleaseViewSet(viewsets.ModelViewSet):
queryset = Release.objects.all()
serializer_class = ReleaseSerializer
filter_class = ReleaseFilter
and I have these two filters (using DRFF):
class ReleaseFilter(filters.FilterSet):
class Meta:
model = Release
fields = {
'price': '__all__',
'version_code': '__all__',
}
class ApplicationFilter(filters.FilterSet):
releases = filters.RelatedFilter(
ReleaseFilter,
queryset=Release.objects.all()
)
class Meta:
model = Application
fields = {
'package_name': '__all__',
}
My REST API is running on localhost:9000/api/v1/
but, when I try to see the Application view (in the browser: "GET /api/v1/application/") I get
this error: "AttributeError: 'NoneType' object has no attribute 'update'"
This is the Traceback for this error:
Internal Server Error: /api/v1/application/
Traceback (most recent call last):
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/django/core/handlers/base.py", line 217, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/django/core/handlers/base.py", line 215, in _get_response
response = response.render()
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/django/template/response.py", line 107, in render
self.content = self.rendered_content
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/rest_framework/response.py", line 72, in rendered_content
ret = renderer.render(self.data, accepted_media_type, context)
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/rest_framework/renderers.py", line 706, in render
context = self.get_context(data, accepted_media_type, renderer_context)
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/rest_framework/renderers.py", line 683, in get_context
'filter_form': self.get_filter_form(data, view, request),
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/rest_framework/renderers.py", line 618, in get_filter_form
html = backend().to_html(request, queryset, view)
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/django_filters/rest_framework/backends.py", line 61, in to_html
filter_instance = filter_class(request.query_params, queryset=queryset, request=request)
File "/home/jfsanchez/Projects/kiosko/lib/python3.5/site-packages/django_filters/filterset.py", line 186, in __init__
self.filters = copy.deepcopy(self.base_filters)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 320, in _reconstruct
value = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 297, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python3.5/copy.py", line 155, in deepcopy
y = copier(x, memo)
File "/usr/lib/python3.5/copy.py", line 243, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python3.5/copy.py", line 182, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python3.5/copy.py", line 306, in _reconstruct
y.__dict__.update(state)
AttributeError: 'NoneType' object has no attribute 'update'
[09/Nov/2017 14:49:29] "GET /api/v1/application/ HTTP/1.1" 500 664601
And this is my (mainly) virtualenv stack:
Django==1.11.4
django-filters==0.2.1
djangorestframework==3.6.4
djangorestframework-filters==0.10.2
Can anyone help me to fix this?
What's the problem here? What do I'm doing wrong?
Thanks!
django-filters==0.2.1
Hi @jfsanchez-gh. django-filters
is not actually the correct package. What's the version number for django-filter
(note the lack of a trailing 's')?
Hi @rpkilby I have django-filter==1.0.4.
Try upgrading to django-filter==1.1.0
.
@rpkilby Upgraded to django-filter==1.1.0, but I still get exactly the same error here (:.
Hi @jfsanchez-g - I'm closing this for now, as there's nothing currently actionable. If you can provide more details, I'm more than happy to reopen and help debug the issue. I've started a #204 that contains tests for this. If you want to add to the tests, you can create a PR against my personal fork, or just post here in the comments.
Also, If you were able to figure out what was going on, a response would be greatly appreciated (as it might help future users).