-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Python Drivers
-
Not Needed
-
None
-
None
-
None
-
None
-
None
-
None
Reported on GitHub PR 412:
I ran into a problem during a transaction when I call the POST create method in the view and try to create documents through the serializer:
class CreateTariff(TariffsSerializer): @transaction.atomic(using="mongodb") def create(self, validated_data): ...
This error occurs spontaneously and always at the first call to the endpoints API.
File: C\test\venv\lib\site-packages\rest_framework\views.py in dispatch (line 506) response = handler(request, *args, **kwargs) File: C:\test\venv\lib\site-packages\rest_framework\mixins.py in create (line 19) self.perform_create(serializer) File: C:\test\venv\lib\site-packages\rest_framework\mixins.py in perform_create (line 24) serializer.save() File: C:\test\venv\lib\site-packages\rest_framework\serializers.py in save (line 208) self.instance = self.create(validated_data) ... File: C:\test\venv\lib\site-packages\django_mongodb_backend\transaction.py in __enter__ (line 29) connection.start_transaction_mongo() File: C:\test\venv\lib\site-packages\django\utils\asyncio.py in inner (line 26) return func(*args, **kwargs) File: C:\test\venv\lib\site-packages\django_mongodb_backend\base.py in start_transaction_mongo (line 275) self.session = self.connection.start_session() Error: 'NoneType' object has no attribute 'start_session'
As I understand it, it occurs due to the fact that the connection lazily creates a connection (connection.connection) during the entry into the transaction.