You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I found this issue when trying tastypie swagger on some Resources created from inherited models.
This may be more general and related to the handling of OneToOne fields...
Here is the code:
from django.db import models
from tastypie.resources import ModelResource
class SampleModel(models.Model):
pass
class InheritedSampleModel(SampleModel):
pass
class SampleResource(ModelResource):
class Meta():
queryset = SampleModel.objects.all()
resource_name = "sample"
pass
class InheritedSampleResource(ModelResource):
class Meta():
queryset = InheritedSampleModel.objects.all()
resource_name = "inheritedsample"
pass
and the traceback:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/api/v1/doc/schema/inheritedsample/?api_key=special-key
Django Version: 1.5.8
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'tastypie_swagger')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
113. response = callback(request, *callback_args, **callback_kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
86. return handler(request, *args, **kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/views/generic/base.py" in get
153. context = self.get_context_data(**kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/tastypie_swagger/views.py" in get_context_data
125. mapping = ResourceSwaggerMapping(resource)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py" in __init__
71. self.resource_pk_type = self.get_pk_type()
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py" in get_pk_type
77. return DJANGO_FIELD_TYPE.get(self.resource._meta.object_class._meta.pk.related_field, 'unknown')
Exception Type: AttributeError at /api/v1/doc/schema/inheritedsample/
Exception Value: 'OneToOneField' object has no attribute 'related_field'
Using tastypie v 0.11.1 and tastypie-swagger master (sha 3d3b2b4) . Resource that are related to parent models (SampleModel in the example) are working fine.
Thanks for all the good work!
The text was updated successfully, but these errors were encountered:
Hey, thanks for the report.
It seems that we need to handle OneToOneField with special care... I can't remember on the top of my head where the related_field could be on such a field but it is probably defined somewhere else.
Do you mind giving it a go and try to fix it ? That would be awesome as I don't have much time to spend writing code for this project nowadays.
Something seems to be wrong, though. From your stack trace, the error seems to originate from tastypie_swagger/mapping.py:77. That line does not seem to correspond to the return statement at all, either in the ref you quoted, or in the current master branch.
Worse, I can't find code that even looks like that in either of these refs. I can find the line self.resource_pk_type = self.get_pk_type(), but that references a function that doesn't look like the one in the final line of that stack trace.
Hello,
I found this issue when trying tastypie swagger on some Resources created from inherited models.
This may be more general and related to the handling of OneToOne fields...
Here is the code:
and the traceback:
Using tastypie v 0.11.1 and tastypie-swagger master (sha 3d3b2b4) . Resource that are related to parent models (SampleModel in the example) are working fine.
Thanks for all the good work!
The text was updated successfully, but these errors were encountered: