Comments (8)
Hey, yes I will merge #91 as soon as possible, this should help you with the coverage :)
from odmantic.
Closed by #227
from odmantic.
Nice catch @Olegt0rr
In MongoDB transactions are not available for Standalone.
Do you have some references about this ?
The only transaction requirements I found were those https://docs.mongodb.com/manual/core/write-operations-atomicity/
Edit: Actually, it's stated that this would only work on replicaSets
from odmantic.
To find out if we're connected to a replicaset or not, i found another way, using the db.serverStatus command:
server_status = await self.database.command({'serverStatus' :1})
is_standalone = "repl" not in server_status
I tried to use the _server_property
you describe but I couldn't find it on my local client.
It would be probably faster to use it as it would avoid to send an extra request to the database.
from odmantic.
Do you have some references about this ?
https://docs.mongodb.com/manual/core/transactions-production-consideration/#feature-compatibility
Replica Set (4.0+) and Sharded Cluster (4.2+) support transactions.
Standalone is not listed here.
Also you can run an experiment: pass session
to request and your PR tester will answer with error
i found another way, using the db.serverStatus command
This way requires server admin role:
not authorized on admin to execute command
For self.client._server_property('server_type')
- readWrite
role is enough.
I've found it in pymongo
similar solution:
https://github.com/mongodb/mongo-python-driver/blob/6b0123594aeb6d4fa618568a28cab3344c5422f0/pymongo/mongo_client.py#L1033-L1039
Also added request to MongoDB jira: https://jira.mongodb.org/browse/PYTHON-2476
from odmantic.
This way requires server admin role:
not authorized on admin to execute command
Yes
Thanks for creating the request in Jira !
I just saw an anwser there:
Bernie Hackett added a comment - Dec 25 2020 03:30:26 PM GMT+0000
The easiest way to do what you want, with no API changes, is to call the ismaster command. If the msg field is set to "isdbgrid" you're connected to a mongos. If the setname field is set you're connected to a replica set memeber. Otherwise you're connected to a standalone.
This looks like a very good solution. We will have to check the version as well to make sure sharded cluster are 4.2+.
To add these commands in the Engine initializer, we might have to gather the event loop held by the motor client or maybe access the underlying pymongo client (I'm not sure it's doable in a clean way for this one)
from odmantic.
Seems calling self.client._server_property('server_type')
still easiest way 😭
from odmantic.
Need some help to finish tests coverage
from odmantic.
Related Issues (20)
- EmbeddedModel indexes HOT 1
- odmantic Is it stable?
- Preserve document fields ordering HOT 1
- Time Series support
- [Feature]: Add support for mixing models.
- ValueError: 'Config.use_enum_values' is not supported
- Cannot support motor time zone problem HOT 2
- Can't change a field in a copied embedded model that's part of a collection #228
- When the time is inserted into the database HOT 2
- Getting OperationFailure error when trying to find using the $near operator HOT 1
- Abstract models HOT 1
- is_type_mutable returns true for Literal types
- `database` argument for `Engine`s defaulted to `"test"` is unexpected
- Union of embedded models regression
- Exclude a field from serialization and saving into database
- Embedded Model Exclude None Not Functioning HOT 1
- Support native validator
- Using the union operator in model breaks HOT 1
- FastAPI schema can not show the fields in parent odmantic.Model class
- Add support for Pydantic V2 HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from odmantic.