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

Works editor custom lists endpoints not handling library list ownership (PP-1962) #2186

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

jonathangreen
Copy link
Member

Description

Previously if a work was in multiple libraries, in the admin UI, in the work list editor, you would see all the lists it was part of, even if those lists did not belong to the current library. And if you tried to edit the works list membership, it would fail with AttributeError: 'NoneType' object has no attribute 'get'.

This PR adds:

  • Pydantic validation for the data submitted to the work editor custom list end point
  • Does some refactoring to the works editor controller custom lists functions
    • Added types
    • Make sure the current library is being respected
  • Added tests to cover the new checks

Motivation and Context

Troubleshooting this trace-back from our logs:

Traceback (most recent call last):
  File "/var/www/circulation/env/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/circulation/env/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/var/www/circulation/src/palace/manager/api/routes.py", line 120, in decorated
    return f(*args, **kwargs)
  File "/var/www/circulation/src/palace/manager/api/admin/routes.py", line 84, in decorated
    v = f(*args, **kwargs)
  File "/var/www/circulation/src/palace/manager/api/admin/routes.py", line 57, in decorated
    return f(*args, **kwargs)
  File "/var/www/circulation/src/palace/manager/api/admin/routes.py", line 75, in decorated
    return f(*args, **kwargs)
  File "/var/www/circulation/src/palace/manager/api/admin/routes.py", line 167, in work_custom_lists
    return app.manager.admin_work_controller.custom_lists(identifier_type, identifier)
  File "/var/www/circulation/src/palace/manager/api/admin/controller/work_editor.py", line 699, in custom_lists
    submitted_ids = [l.get("id") for l in lists if l.get("id")]
  File "/var/www/circulation/src/palace/manager/api/admin/controller/work_editor.py", line 699, in <listcomp>
    submitted_ids = [l.get("id") for l in lists if l.get("id")]
AttributeError: 'NoneType' object has no attribute 'get'

JIRA:

How Has This Been Tested?

  • Tested locally with production data
  • Running unit tests in CI

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@jonathangreen jonathangreen added the bug Something isn't working label Nov 22, 2024
@jonathangreen jonathangreen requested a review from a team November 22, 2024 17:40
Copy link

codecov bot commented Nov 22, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 4 lines in your changes missing coverage. Please review.

Project coverage is 91.03%. Comparing base (1d1b4eb) to head (de57151).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...palace/manager/api/admin/controller/work_editor.py 91.83% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2186      +/-   ##
==========================================
+ Coverage   91.01%   91.03%   +0.02%     
==========================================
  Files         361      362       +1     
  Lines       41205    41222      +17     
  Branches     8849     8850       +1     
==========================================
+ Hits        37504    37528      +24     
+ Misses       2425     2421       -4     
+ Partials     1276     1273       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@jonathangreen jonathangreen changed the title Works editor custom lists endpoints not handling library list ownership Works editor custom lists endpoints not handling library list ownership (PP-1962) Nov 22, 2024
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 🎉

@jonathangreen jonathangreen merged commit 64b5368 into main Nov 22, 2024
21 checks passed
@jonathangreen jonathangreen deleted the bugfix/works-customlist-library branch November 22, 2024 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants