Hello,
I have found very strange behaviour.
In my app I have one serializer for partial update and one for data with 
nested representations.
This block of code: 
@database_sync_to_async
   def _update_order(self, content):
       instance = Order.objects.get(id=content.get('id'))
       serializer = UpdateOrderSerializer(data=content, partial=True)
       serializer.is_valid(raise_exception=True)
       order = serializer.update(instance, serializer.validated_data)
       #if u remove print u get an error ???
       print(order)
       return order

Couses error


   1. app_1    | Exception inside application: You cannot call this from an 
   async context - use a thread or sync_to_async.
   2. app_1    | Traceback (most recent call last):
   3. app_1    |   File 
   
"/usr/local/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py"
   , line 172, in __get__
   4. app_1    |     rel_obj = self.field.get_cached_value(instance)
   5. app_1    |   File 
   "/usr/local/lib/python3.7/site-packages/django/db/models/fields/mixins.py"
   , line 13, in get_cached_value
   6. app_1    |     return instance._state.fields_cache[cache_name]
   7. app_1    | KeyError: 'premises'
   

But when I uncomment print(order)
Evertything as it should.
I have no idea why if u know im looking forward to hear.

Full code:
https://github.com/swrzalek/onboard/blob/master/app/orders/consumers.py

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/c96b6e42-e6cf-4cf8-8d3f-6ceaa11e145f%40googlegroups.com.

Reply via email to