Note that there are some explanatory texts on larger screens.

plurals
  1. POTastypie foreign Key relationship 'dict' object has no attribute 'obj'
    primarykey
    data
    text
    <p>I'm having a problem with tastypie and I just can't find what caused it. Similar question without answers: <a href="https://stackoverflow.com/questions/18050847/tastypie-foreign-key-relationship-throwing-error">Tastypie foreign key relationship throwing error</a></p> <p>Resource:</p> <pre><code>class VoteResource(ModelResource): choice = fields.ToOneField(ChoiceResource, 'choice', full=True) user = fields.ToOneField(UserResource, 'user') class Meta: queryset = Vote.objects.all() resource_name = 'vote' '''...''' always_return_data = True filtering = { 'id': ALL, 'user': ALL_WITH_RELATIONS, 'choice': ALL_WITH_RELATIONS } def hydrate(self, bundle): bundle.obj.user = bundle.request.user return bundle </code></pre> <p>Request payload for creating the object:</p> <pre><code>{ "choice": "/api/v1/choice/210/" } </code></pre> <p>(user is getting added automatically through hydrate). The exception is thrown in ressources.py inside <code>full_hydrate</code>. According to django console my object is getting loaded correctly.</p> <p>The line inside tastypie causing this is</p> <pre><code>setattr(bundle.obj, field_object.attribute, value.obj) # value obj is the evil one </code></pre> <p><a href="https://github.com/toastdriven/django-tastypie/blob/master/tastypie/resources.py#L893" rel="nofollow noreferrer">Tastypie sourcecode here</a></p> <p>What's killing me is, that it worked like 2 days ago. I added 1 other resource without touching choice, user or any other connected with the model. I checked the recent commit history and the resource is untouched. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload