Skip to content

Commit

Permalink
raise ValidationError instead of CallError (#15097)
Browse files Browse the repository at this point in the history
Co-authored-by: caleb <[email protected]>
  • Loading branch information
bugclerk and yocalebo authored Dec 3, 2024
1 parent e9753b2 commit 0d593d1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/middlewared/middlewared/plugins/keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from truenas_api_client import Client, ClientException

from middlewared.service_exception import CallError, MatchNotFound
from middlewared.service_exception import CallError, MatchNotFound, ValidationError
from middlewared.schema import accepts, Bool, Dict, Int, List, Patch, Password, Ref, returns, Str, ValidationErrors
from middlewared.service import CRUDService, private
import middlewared.sqlalchemy as sa
Expand Down Expand Up @@ -398,12 +398,14 @@ async def do_delete(self, id_, options):
"""

instance = await self.get_instance(id_)

for delegate in TYPES[instance["type"]].used_by_delegates:
delegate = delegate(self.middleware)
for row in await delegate.query(instance["id"]):
if not options["cascade"]:
raise CallError("This credential is used and no cascade option is specified")
raise ValidationError(
"options.cascade",
"This credential is used and no cascade option is specified"
)

await delegate.unbind(row)

Expand Down

0 comments on commit 0d593d1

Please sign in to comment.