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