Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docassemble/AssemblyLine/al_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import secrets
import string


__all__ = [
"ALAddendumField",
"ALAddendumFieldDict",
Expand Down
30 changes: 10 additions & 20 deletions docassemble/AssemblyLine/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,13 @@ def get_interview_metadata(
Returns:
Dict[str, Any]: The metadata associated with the interview
"""
sql = text(
"""
sql = text("""
SELECT data
FROM jsonstorage
WHERE filename = :filename
AND tags = :tags
AND key = :session_id
"""
)
""")
with db.connect() as con:
row = con.execute(
sql,
Expand Down Expand Up @@ -590,8 +588,7 @@ def find_matching_sessions(
else:
filename_condition = "TRUE" # If no filenames are provided, this condition does not filter anything.

get_sessions_query = text(
f"""
get_sessions_query = text(f"""
SELECT * FROM (
SELECT DISTINCT ON (userdict.key) userdict.indexno,
userdict.filename as filename,
Expand All @@ -618,8 +615,7 @@ def find_matching_sessions(
) AS unique_sessions
ORDER BY modtime DESC
LIMIT :limit OFFSET :offset;
"""
)
""")

if offset < 0:
offset = 0
Expand Down Expand Up @@ -703,17 +699,15 @@ def delete_interview_sessions(
"User that is not logged in does not have permission to delete any sessions"
)
return None
delete_sessions_query = text(
"""
delete_sessions_query = text("""
DELETE FROM userdictkeys
WHERE user_id = :user_id
AND
filename != :filename_to_exclude
AND
filename != :current_filename
;
"""
)
""")
if not user_id:
user_id = user_info().id
if user_id != user_info().id and not user_has_privilege(["developer", "admin"]):
Expand Down Expand Up @@ -1743,15 +1737,13 @@ def to_signed_32(x: int) -> int:
)

# 4) Try UPDATE first, using CAST() instead of ::jsonb
update_sql = text(
"""
update_sql = text("""
UPDATE jsonstorage
SET data = jsonstorage.data || CAST(:data AS jsonb)
WHERE key = :session_id
AND filename = :filename
AND tags = :tags
"""
)
""")
result = con.execute(
update_sql,
{
Expand All @@ -1764,12 +1756,10 @@ def to_signed_32(x: int) -> int:

# 5) If nothing was updated, INSERT
if (result.rowcount or 0) == 0:
insert_sql = text(
"""
insert_sql = text("""
INSERT INTO jsonstorage (key, filename, tags, data)
VALUES (:session_id, :filename, :tags, CAST(:data AS jsonb))
"""
)
""")
con.execute(
insert_sql,
{
Expand Down
Loading