Skip to content

Commit

Permalink
Try potential fix for #850
Browse files Browse the repository at this point in the history
  • Loading branch information
nonprofittechy committed May 13, 2024
1 parent 05f5485 commit 1ed4e29
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions docassemble/AssemblyLine/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
DALazyTemplate,
DAList,
DAObject,
DAGlobal,
DASet,
format_time,
get_config,
Expand All @@ -23,6 +24,7 @@
set_parts,
set_session_variables,
set_variables,
SQLObject,
url_action,
url_ask,
user_has_privilege,
Expand Down Expand Up @@ -62,6 +64,7 @@
"get_saved_interview_list",
"interview_list_html",
"is_file_like",
"is_unsafe_to_store",
"is_valid_json",
"load_interview_answers",
"load_interview_json",
Expand Down Expand Up @@ -244,14 +247,33 @@ def is_file_like(obj: Any) -> bool:
ALStaticDocument,
ALExhibit,
ALExhibitList,
DALazyTemplate,
),
):
return True

return False


def is_unsafe_to_store(obj: Any) -> bool:
"""
Return True if the object is unsafe to store and retreive from a session.
Most objects are safe to store and retrieve from a session, but we currently screen out:
- File-like objects, e.g., DAFile and Assembly Line variants for attachments
- DALazyTemplate
- SQLObject objects
- DAGlobal objects
Args:
obj (Any): The object to test
Returns:
bool: True if the object is unsafe to store in a session.
"""
return is_file_like(obj) or isinstance(obj, (DAGlobal, SQLObject, DALazyTemplate))


def set_interview_metadata(
filename: str, session_id: int, data: Dict, metadata_key_name="metadata"
) -> None:
Expand Down Expand Up @@ -1113,7 +1135,7 @@ def get_filtered_session_variables(
key, value = items_to_check.pop()

# This condition only will apply to "top level" variables
if is_file_like(value):
if is_unsafe_to_store(value):
del all_vars[key]
continue

Expand All @@ -1125,7 +1147,7 @@ def get_filtered_session_variables(
) # skip over properties etc. vs using object.dir()
for attr in attr_list:
attr_val = object.__getattribute__(value, attr)
if is_file_like(attr_val):
if is_unsafe_to_store(attr_val):
delattr(value, attr)
elif isinstance(attr_val, (DAList, DASet, DAObject)):
items_to_check.append(
Expand All @@ -1135,7 +1157,7 @@ def get_filtered_session_variables(
if isinstance(value, (DAList, DASet)):
new_elements = []
for subitem in value.elements:
if not is_file_like(subitem):
if not is_unsafe_to_store(subitem):
new_elements.append(subitem)
if isinstance(subitem, (DAList, DASet, DAObject)):
items_to_check.append((None, subitem))
Expand Down

0 comments on commit 1ed4e29

Please sign in to comment.