Spaces:
Building
Building
Update config_provider.py
Browse files- config_provider.py +63 -40
config_provider.py
CHANGED
@@ -29,7 +29,14 @@ class ConfigProvider:
|
|
29 |
_lock = threading.RLock() # Reentrant lock for nested calls
|
30 |
_file_lock = threading.Lock() # Separate lock for file operations
|
31 |
_CONFIG_PATH = Path(__file__).parent / "service_config.jsonc"
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
@classmethod
|
34 |
def get(cls) -> ServiceConfig:
|
35 |
"""Get cached configuration - thread-safe"""
|
@@ -147,7 +154,11 @@ class ConfigProvider:
|
|
147 |
|
148 |
# Check for race condition
|
149 |
if config.last_update_date and current_config.last_update_date:
|
150 |
-
|
|
|
|
|
|
|
|
|
151 |
raise RaceConditionError(
|
152 |
"Configuration was modified by another user",
|
153 |
current_user=username,
|
@@ -277,25 +288,27 @@ class ConfigProvider:
|
|
277 |
|
278 |
if not project:
|
279 |
raise ResourceNotFoundError("project", project_id)
|
280 |
-
|
281 |
-
log_debug(f"๐ Project update check - Project ID: {project_id}")
|
282 |
-
log_debug(f"๐ Expected last_update: {expected_last_update}")
|
283 |
-
log_debug(f"๐ Actual last_update: {project.last_update_date}")
|
284 |
-
log_debug(f"๐ Type of expected: {type(expected_last_update)}")
|
285 |
-
log_debug(f"๐ Type of actual: {type(project.last_update_date)}")
|
286 |
|
287 |
-
# Check race condition
|
288 |
if expected_last_update is not None and expected_last_update != '':
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
|
300 |
# Update fields
|
301 |
for key, value in update_data.items():
|
@@ -462,16 +475,21 @@ class ConfigProvider:
|
|
462 |
raise ValidationError("Published versions cannot be modified")
|
463 |
|
464 |
# Check race condition
|
465 |
-
if expected_last_update is not None:
|
466 |
-
if version.last_update_date
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
|
|
|
|
|
|
|
|
|
|
475 |
|
476 |
# Update fields
|
477 |
for key, value in update_data.items():
|
@@ -556,17 +574,22 @@ class ConfigProvider:
|
|
556 |
raise ResourceNotFoundError("api", api_name)
|
557 |
|
558 |
# Check race condition
|
559 |
-
if expected_last_update is not None:
|
560 |
-
if api.last_update_date
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
|
|
|
|
|
|
|
|
|
|
570 |
# Update fields
|
571 |
for key, value in update_data.items():
|
572 |
if hasattr(api, key) and key not in ['name', 'created_date', 'created_by', 'last_update_date']:
|
|
|
29 |
_lock = threading.RLock() # Reentrant lock for nested calls
|
30 |
_file_lock = threading.Lock() # Separate lock for file operations
|
31 |
_CONFIG_PATH = Path(__file__).parent / "service_config.jsonc"
|
32 |
+
|
33 |
+
@staticmethod
|
34 |
+
def _normalize_date(date_str: Optional[str]) -> str:
|
35 |
+
"""Normalize date string for comparison"""
|
36 |
+
if not date_str:
|
37 |
+
return ""
|
38 |
+
return date_str.replace(' ', 'T').replace('+00:00', 'Z').replace('.000Z', 'Z')
|
39 |
+
|
40 |
@classmethod
|
41 |
def get(cls) -> ServiceConfig:
|
42 |
"""Get cached configuration - thread-safe"""
|
|
|
154 |
|
155 |
# Check for race condition
|
156 |
if config.last_update_date and current_config.last_update_date:
|
157 |
+
# Tarihleri normalize et
|
158 |
+
expected_normalized = cls._normalize_date(config.last_update_date)
|
159 |
+
actual_normalized = cls.normalize_date(current_config.last_update_date)
|
160 |
+
|
161 |
+
if expected_normalized != actual_normalized:
|
162 |
raise RaceConditionError(
|
163 |
"Configuration was modified by another user",
|
164 |
current_user=username,
|
|
|
288 |
|
289 |
if not project:
|
290 |
raise ResourceNotFoundError("project", project_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
+
# Check race condition
|
293 |
if expected_last_update is not None and expected_last_update != '':
|
294 |
+
if project.last_update_date:
|
295 |
+
# Datetime objesini string'e รงevir
|
296 |
+
actual_date_str = project.last_update_date.isoformat() if isinstance(project.last_update_date, datetime) else str(project.last_update_date)
|
297 |
+
|
298 |
+
# Tarihleri normalize et
|
299 |
+
expected_normalized = cls._normalize_date(expected_last_update)
|
300 |
+
actual_normalized = cls._normalize_date(actual_date_str)
|
301 |
+
|
302 |
+
if expected_normalized != actual_normalized:
|
303 |
+
log_info(f"๐ Date mismatch - Expected: {expected_normalized}, Actual: {actual_normalized}")
|
304 |
+
raise RaceConditionError(
|
305 |
+
f"Project '{project.name}' was modified by another user",
|
306 |
+
current_user=username,
|
307 |
+
last_update_user=project.last_update_user,
|
308 |
+
last_update_date=project.last_update_date,
|
309 |
+
entity_type="project",
|
310 |
+
entity_id=project_id
|
311 |
+
)
|
312 |
|
313 |
# Update fields
|
314 |
for key, value in update_data.items():
|
|
|
475 |
raise ValidationError("Published versions cannot be modified")
|
476 |
|
477 |
# Check race condition
|
478 |
+
if expected_last_update is not None and expected_last_update != '':
|
479 |
+
if version.last_update_date:
|
480 |
+
# Tarihleri normalize et
|
481 |
+
expected_normalized = cls._normalize_date(expected_last_update)
|
482 |
+
actual_normalized = cls._normalize_date(version.last_update_date)
|
483 |
+
|
484 |
+
if expected_normalized != actual_normalized:
|
485 |
+
raise RaceConditionError(
|
486 |
+
f"Version {version_no} was modified by another user",
|
487 |
+
current_user=username,
|
488 |
+
last_update_user=version.last_update_user,
|
489 |
+
last_update_date=version.last_update_date,
|
490 |
+
entity_type="version",
|
491 |
+
entity_id=f"{project_id}:{version_no}"
|
492 |
+
)
|
493 |
|
494 |
# Update fields
|
495 |
for key, value in update_data.items():
|
|
|
574 |
raise ResourceNotFoundError("api", api_name)
|
575 |
|
576 |
# Check race condition
|
577 |
+
if expected_last_update is not None and expected_last_update != '':
|
578 |
+
if api.last_update_date:
|
579 |
+
# Tarihleri normalize et
|
580 |
+
expected_normalized = cls._normalize_date(expected_last_update)
|
581 |
+
actual_normalized = cls._normalize_date(api.last_update_date)
|
582 |
+
|
583 |
+
if expected_normalized != actual_normalized:
|
584 |
+
raise RaceConditionError(
|
585 |
+
f"API '{api.name}' was modified by another user",
|
586 |
+
current_user=username,
|
587 |
+
last_update_user=api.last_update_user,
|
588 |
+
last_update_date=api.last_update_date,
|
589 |
+
entity_type="api",
|
590 |
+
entity_id=api.name
|
591 |
+
)
|
592 |
+
|
593 |
# Update fields
|
594 |
for key, value in update_data.items():
|
595 |
if hasattr(api, key) and key not in ['name', 'created_date', 'created_by', 'last_update_date']:
|