Skip to content

Commit 95b5e3f

Browse files
authored
Merge pull request #506 from MongoEngine/uuid_default
Changed: Flask-Mongoengine will set uuidRepresentation=standard if not specified in other configuration
2 parents ed5be28 + 95e8567 commit 95b5e3f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

flask_mongoengine/connection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ def create_connections(config: dict):
121121
connections = {}
122122
for connection_setting in connection_settings:
123123
alias = connection_setting.setdefault(
124-
"alias", mongoengine.DEFAULT_CONNECTION_NAME
124+
"alias",
125+
mongoengine.DEFAULT_CONNECTION_NAME,
125126
)
127+
connection_setting.setdefault("uuidRepresentation", "standard")
126128
connections[alias] = mongoengine.connect(**connection_setting)
127129

128130
return connections

tests/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ def app() -> Flask:
3838

3939
@pytest.fixture()
4040
def db(app) -> MongoEngine:
41-
app.config["MONGODB_HOST"] = "mongodb://localhost:27017/flask_mongoengine_test_db"
41+
app.config["MONGODB_SETTINGS"] = [
42+
{
43+
"db": "flask_mongoengine_test_db",
44+
"host": "localhost",
45+
"port": 27017,
46+
"alias": "default",
47+
"uuidRepresentation": "standard",
48+
}
49+
]
4250
test_db = MongoEngine(app)
4351
db_name = (
4452
test_db.connection["default"].get_database("flask_mongoengine_test_db").name

tests/test_json.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
@pytest.fixture()
88
def extended_db(app):
99
app.json_encoder = DummyEncoder
10-
app.config["MONGODB_HOST"] = "mongodb://localhost:27017/flask_mongoengine_test_db"
10+
app.config["MONGODB_SETTINGS"] = [
11+
{
12+
"db": "flask_mongoengine_test_db",
13+
"host": "localhost",
14+
"port": 27017,
15+
"alias": "default",
16+
"uuidRepresentation": "standard",
17+
}
18+
]
1119
test_db = MongoEngine(app)
1220
db_name = (
1321
test_db.connection["default"].get_database("flask_mongoengine_test_db").name

0 commit comments

Comments
 (0)