Skip to content
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

Better handling of project path AttributeError #641

Merged
merged 2 commits into from
Aug 30, 2024
Merged
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
16 changes: 13 additions & 3 deletions viewer/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,19 @@ def validate(self, data):

base_object_key, project_path = view.filter_permissions.split('__', 1)
base_start_obj = data[base_object_key]
project_obj = (
getattr(base_start_obj, project_path) if project_path else base_start_obj
)
# Assume we're using the base object,
# but swap it out of there's a project path.
project_obj = base_start_obj
if project_path:
try:
project_obj = getattr(base_start_obj, project_path)
except AttributeError as exc:
# Something's gone wrong trying to lookup the project.
# Get the objects content and dump it for analysis...
msg = f"There is no Project at '{project_path}' ({view.filter_permissions})"
logger.error("%s - vars(base_start_obj)=%s", msg, vars(base_start_obj))
raise serializers.ValidationError(msg) from exc
assert project_obj
# Now get the proposals from the Project(s)...
if project_obj.__class__.__name__ == "ManyRelatedManager":
# Potential for many proposals...
Expand Down