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

Filter on library when checking lane name unique (PP-1967) #2190

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

jonathangreen
Copy link
Member

Description

This PR does a small bit of refactoring to DRY the check we use for lane name uniqueness and fixes a bug where the check for lane name uniqueness

Previously one of the checks was missing a filter on the lanes library. Making it so that you couldn't create a lane with the same name as any other lane in the CM, rather then any other lane with the same library.

Motivation and Context

Debugging this unhandled traceback:

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 617, in lanes
    return app.manager.admin_lanes_controller.lanes()
  File "/var/www/circulation/src/palace/manager/api/admin/controller/lanes.py", line 94, in lanes
    old_lane = get_one(
  File "/var/www/circulation/src/palace/manager/sqlalchemy/util.py", line 99, in get_one
    return q.one()  # type: ignore[no-any-return]
  File "/var/www/circulation/env/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2870, in one
    return self._iter().one()
  File "/var/www/circulation/env/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1522, in one
    return self._only_one_row(
  File "/var/www/circulation/env/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 614, in _only_one_row
    raise exc.MultipleResultsFound(
sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when exactly one was required

How Has This Been Tested?

  • Running unit tests

Checklist

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

@jonathangreen jonathangreen added the bug Something isn't working label Nov 25, 2024
@jonathangreen jonathangreen requested a review from a team November 25, 2024 18:51
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.05%. Comparing base (8d10cab) to head (5fabcdc).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2190   +/-   ##
=======================================
  Coverage   91.05%   91.05%           
=======================================
  Files         363      363           
  Lines       41218    41219    +1     
  Branches     8847     8846    -1     
=======================================
+ Hits        37530    37531    +1     
  Misses       2417     2417           
  Partials     1271     1271           

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

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.

This looks good to me and can go in as-is.

Should we update the LANE_WITH_PARENT_AND_DISPLAY_NAME_ALREADY_EXISTS problem detail to make it more clear that the constraint is per-library:

LANE_WITH_PARENT_AND_DISPLAY_NAME_ALREADY_EXISTS = pd(
    "http://librarysimplified.org/terms/problem/lane-with-parent-and-display-name-already-exists",
    status_code=400,
    title=_("Lane with parent and display name already exists"),
    detail=_(
        "You cannot create a lane with the same parent and display name as an existing lane."
    ),
)

e.g.:

    ...
    title=_("Lane with parent and display name already exists for this library"),
    detail=_(
        "You cannot create a lane with the same parent and display name as an existing lane within the same library."
    ),
    

@jonathangreen jonathangreen merged commit b5b0522 into main Nov 26, 2024
21 checks passed
@jonathangreen jonathangreen deleted the bugfix/lane-with-same-name-different-library branch November 26, 2024 00:34
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