Thanks for answer. When I in request object I send id of premises it works 
fine. 
Request which led to error contained only id of order and one additional 
field.

W dniu poniedziałek, 18 maja 2020 23:48:17 UTC+2 użytkownik Xavier Ordoquy 
napisał:
>
> You probably have a queryset somewhere that is evaluated with the print 
> and isn’t without.
> Point is, it may delay synchronous DB requests in an asynchronous code 
> which would raise the error.
>
> Regards,
> Xavier O.
> Le 18 mai 2020 à 22:47 +0200, sebastian wrzalek <stia...@gmail.com 
> <javascript:>>, a écrit :
>
> 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 <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-rest-framework/c96b6e42-e6cf-4cf8-8d3f-6ceaa11e145f%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-rest-framework/c96b6e42-e6cf-4cf8-8d3f-6ceaa11e145f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>

-- 
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/edfdb008-972d-4579-ab13-03e91d3e82ed%40googlegroups.com.

Reply via email to