-
-
Notifications
You must be signed in to change notification settings - Fork 40
fix(lists): get_entry cursor scope + reorder rollback on failure (tsk-u23vjy) #2361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ### Fixed | ||
|
|
||
| - Project list entries: `get_entry` no longer reads cursor metadata after the | ||
| cursor closes, and a failed reorder now rolls back its partial updates so a | ||
| later unrelated write cannot commit a half-applied ordering (tsk-u23vjy, | ||
| fix-forward of #2183). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,8 +174,9 @@ async def get_entry(self, entry_id: str) -> dict | None: | |
| row = await cur.fetchone() | ||
| if row is None: | ||
| return None | ||
| keys = [d[0] for d in cur.description] | ||
| return dict(zip(keys, row)) | ||
| # cur.description is only guaranteed while the cursor is open. | ||
| keys = [d[0] for d in cur.description] | ||
| return dict(zip(keys, row)) | ||
|
|
||
| async def list_entries( | ||
| self, | ||
|
|
@@ -259,16 +260,25 @@ async def delete_entry(self, entry_id: str) -> bool: | |
| return cursor.rowcount == 1 | ||
|
|
||
| async def reorder_entries(self, project_id: str, list_id: str, entries: list[dict]) -> bool: | ||
| for entry in entries: | ||
| cursor = await self._db.execute( | ||
| "UPDATE project_list_entries SET position = ?, updated_at = ? " | ||
| "WHERE id = ? AND project_id = ? AND list_id = ?", | ||
| (entry["position"], time.time(), entry["id"], project_id, list_id), | ||
| ) | ||
| if cursor.rowcount == 0: | ||
| await self._db.rollback() | ||
| return False | ||
| await self._db.commit() | ||
| try: | ||
| for entry in entries: | ||
| cursor = await self._db.execute( | ||
| "UPDATE project_list_entries SET position = ?, updated_at = ? " | ||
| "WHERE id = ? AND project_id = ? AND list_id = ?", | ||
| (entry["position"], time.time(), entry["id"], project_id, list_id), | ||
| ) | ||
| if cursor.rowcount == 0: | ||
| await self._db.rollback() | ||
| return False | ||
| await self._db.commit() | ||
| except BaseException: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [WARNING]:
Reply with |
||
| # Without this, the UPDATEs already issued stay pending on the | ||
| # shared connection and the next unrelated commit() flushes a | ||
| # half-applied reorder. BaseException, not Exception: task | ||
| # cancellation (CancelledError) must also roll back, and commit() | ||
| # itself is inside the guard for the same reason. | ||
| await self._db.rollback() | ||
| raise | ||
| return True | ||
|
|
||
| async def _get_next_position(self, project_id: str, list_id: str) -> int: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.