-
Notifications
You must be signed in to change notification settings - Fork 0
Manage file added again to same session, data is updated. #21
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
df35686
caf6fcd
66d8df8
795cc16
19e094f
e425dcf
9eefa2e
f9cef7c
343e978
a0ff5e9
ba0f644
7aef366
70620ab
84bd591
b0d39a6
ee3b6c4
006d4cb
fa8e300
820ea31
c753000
01581a4
5e60ef1
385efb9
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 |
|---|---|---|
|
|
@@ -83,6 +83,15 @@ def add_files_to_session( | |
| annex = uuidToObject(uuid=uid, unrestricted=True) | ||
| context_uid_provider = getAdapter(annex, IContextUidProvider) | ||
| context_uid = context_uid_provider.get_context_uid() | ||
| # update data if adding same file to same session | ||
| if annot['uids'].get(uid, -1) == session_id: | ||
| logger.info('File with UID %s is already in session_id %s and data were updated!', uid, session_id) | ||
| # remove old filename to avoid filename being renamed | ||
| old_filename = path.splitext([fn for fn in session["files"] | ||
| if fn['uid'] == uid][0]['filename'])[0] | ||
| existing_files.remove(old_filename) | ||
| remove_files_from_session([uid], remove_empty_session=False) | ||
|
Comment on lines
+93
to
+96
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. Prevent crash when UID mapping is stale. This lookup assumes the UID always exists in 💡 Proposed fix- old_filename = path.splitext([fn for fn in session["files"]
- if fn['uid'] == uid][0]['filename'])[0]
+ old_file = next((fn for fn in session["files"] if fn["uid"] == uid), None)
+ if old_file is None:
+ logger.error(
+ "File UID %s mapped to session %s but missing from session files.",
+ uid, session_id,
+ )
+ continue
+ old_filename = path.splitext(old_file["filename"])[0]🧰 Tools🪛 Ruff (0.15.4)[warning] 95-96: Prefer Replace with (RUF015) 🤖 Prompt for AI Agents |
||
|
|
||
| filename, ext = path.splitext(annex.file.filename or "no_filename.pdf") | ||
| new_filename = get_correct_id(existing_files, filename) | ||
| session["files"].append( | ||
|
|
@@ -353,7 +362,7 @@ def remove_context_from_session(context_uids): | |
| remove_files_from_session(list(c_uids[context_uid])) | ||
|
|
||
|
|
||
| def remove_files_from_session(files_uids): | ||
| def remove_files_from_session(files_uids, remove_empty_session=True): | ||
| """Remove files from their corresponding sessions. | ||
|
|
||
| :param files_uids: list of file UIDs to remove | ||
|
|
@@ -386,7 +395,7 @@ def remove_files_from_session(files_uids): | |
| continue | ||
|
|
||
| del session["files"][i] | ||
| if not session["files"]: | ||
| if not session["files"] and remove_empty_session: | ||
| del sessions[session_id] | ||
| else: | ||
| session["last_update"] = datetime.now() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test doesn’t strictly prove “same session” update behavior.
The second call omits
session_id, so this can still pass if a new session is created. Also,sidfrom Line 472 is unused. Force the same-session path and assert identity/count explicitly.💡 Proposed fix
Based on learnings: In
src/imio/esign/utils.py, when an explicitsession_idis provided toadd_files_to_session(), discriminators are intentionally bypassed.🧰 Tools
🪛 Ruff (0.15.4)
[warning] 472-472: Unpacked variable
sidis never usedPrefix it with an underscore or any other dummy variable pattern
(RUF059)
🤖 Prompt for AI Agents