ciyidogan commited on
Commit
bfe8430
·
verified ·
1 Parent(s): 612dd2d

Update config_provider.py

Browse files
Files changed (1) hide show
  1. config_provider.py +5 -5
config_provider.py CHANGED
@@ -258,8 +258,8 @@ class ConfigProvider:
258
 
259
  return project
260
 
261
- @classmethod
262
- def update_project(cls, project_id: int, update_data: dict, username: str) -> ProjectConfig:
263
  """Update project with optimistic locking"""
264
  with cls._lock:
265
  config = cls.get()
@@ -269,8 +269,8 @@ class ConfigProvider:
269
  raise ResourceNotFoundError("project", project_id)
270
 
271
  # Check race condition
272
- if 'last_update_date' in update_data:
273
- if project.last_update_date != update_data['last_update_date']:
274
  raise RaceConditionError(
275
  f"Project '{project.name}' was modified by another user",
276
  current_user=username,
@@ -282,7 +282,7 @@ class ConfigProvider:
282
 
283
  # Update fields
284
  for key, value in update_data.items():
285
- if hasattr(project, key) and key not in ['id', 'created_date', 'created_by']:
286
  setattr(project, key, value)
287
 
288
  project.last_update_date = datetime.utcnow().isoformat()
 
258
 
259
  return project
260
 
261
+ @classmethod
262
+ def update_project(cls, project_id: int, update_data: dict, username: str, expected_last_update: Optional[str] = None) -> ProjectConfig:
263
  """Update project with optimistic locking"""
264
  with cls._lock:
265
  config = cls.get()
 
269
  raise ResourceNotFoundError("project", project_id)
270
 
271
  # Check race condition
272
+ if expected_last_update is not None:
273
+ if project.last_update_date != expected_last_update:
274
  raise RaceConditionError(
275
  f"Project '{project.name}' was modified by another user",
276
  current_user=username,
 
282
 
283
  # Update fields
284
  for key, value in update_data.items():
285
+ if hasattr(project, key) and key not in ['id', 'created_date', 'created_by', 'last_update_date']:
286
  setattr(project, key, value)
287
 
288
  project.last_update_date = datetime.utcnow().isoformat()