|
8 | 8 |
|
9 | 9 | import abnf |
10 | 10 | import pymongo |
| 11 | +import pymongo.database |
11 | 12 | import werkzeug |
12 | 13 | from flask import Blueprint, Response, abort, request, url_for |
13 | 14 |
|
14 | | -from odata_server import edm |
| 15 | +from odata_server import edm, settings |
15 | 16 | from odata_server.utils import ( |
16 | 17 | build_response_headers, |
17 | 18 | expand_result, |
@@ -79,7 +80,7 @@ def make_setup_state(self, app, options, first_registration=False): |
79 | 80 | and entity_set.custom_insert_business is None |
80 | 81 | ): |
81 | 82 | logger.error( |
82 | | - "EntitySet {} is managing an entity type that contains computed properties. The logic for initializaing those computed properties has to be configured".format( |
| 83 | + "EntitySet {} is managing an entity type that contains computed properties. The logic for initializing those computed properties has to be configured".format( |
83 | 84 | entity_set.Name |
84 | 85 | ) |
85 | 86 | ) |
@@ -126,9 +127,9 @@ def make_setup_state(self, app, options, first_registration=False): |
126 | 127 | } |
127 | 128 | ) |
128 | 129 | ) |
129 | | - entity_set.annotations[ |
130 | | - "Org.OData.Core.V1.ResourcePath" |
131 | | - ] = entity_set.Annotations[-1] |
| 130 | + entity_set.annotations["Org.OData.Core.V1.ResourcePath"] = ( |
| 131 | + entity_set.Annotations[-1] |
| 132 | + ) |
132 | 133 |
|
133 | 134 | resource_path = edm.get_annotation( |
134 | 135 | entity_set, "Org.OData.Core.V1.ResourcePath" |
@@ -273,7 +274,14 @@ def parse_prefer_header(value, version="4.0"): |
273 | 274 | return data |
274 | 275 |
|
275 | 276 |
|
276 | | -def get(mongo, RootEntitySet, subject, id_value, prefers, session=None): |
| 277 | +def get( |
| 278 | + mongo: pymongo.database.Database, |
| 279 | + RootEntitySet, |
| 280 | + subject, |
| 281 | + id_value, |
| 282 | + prefers, |
| 283 | + session=None, |
| 284 | +): |
277 | 285 | anonymous = not isinstance(subject, edm.EntitySet) |
278 | 286 | qs = parse_qs(request.query_string) |
279 | 287 | EntityType = subject.entity_type |
@@ -324,7 +332,11 @@ def get(mongo, RootEntitySet, subject, id_value, prefers, session=None): |
324 | 332 | pipeline.append({"$unwind": f"${prefix}"}) |
325 | 333 |
|
326 | 334 | pipeline.append({"$limit": 1}) |
327 | | - results = tuple(mongo_collection.aggregate(pipeline, session=session)) |
| 335 | + results = tuple( |
| 336 | + mongo_collection.aggregate( |
| 337 | + pipeline, session=session, maxTimeMs=settings.MONGO_SEARCH_MAX_TIME_MS |
| 338 | + ) |
| 339 | + ) |
328 | 340 | if len(results) == 0: |
329 | 341 | abort(404) |
330 | 342 | data = results[0] |
|
0 commit comments