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

Rules: Return 404 when DID rules not found #6334 #6384

Conversation

alexanderrichards
Copy link
Contributor

This PR fixes #6334.

The empty generator on the line

https://github.com/alexanderrichards/rucio/blob/01aa2184041e34584a82669ba846dfedfd8f0f51/lib/rucio/api/rule.py#L163

means that this generator never yields anything but neither does it raise an exception to get caught which would trigger a return value other than 200.

Instead of duplicating the generator and peeking I simply add a counter to see if it ever yields. If not then there were no rules and we can raise RuleNotFound.

@alexanderrichards alexanderrichards force-pushed the patch-6334-Fix_listing_of_DID_rules_when_none_found_ branch from 01aa218 to 1fd25ec Compare November 22, 2023 14:13
@bari12
Copy link
Member

bari12 commented Nov 27, 2023

Hi @alexanderrichards
While this works, I think it slightly misses the semantics of the original issue.

Thus, if an invalid (= non existent) did is given to the rest endpoint (/dids/{scope_name}/rules) then a DIDNotFound exception should be raised. How you implemented it, even if a valid did is given, an exception is raised that no rules exist, but this is not really exception-worthy, since a did can have no rules.

Now what makes this a bit special is that the core call: list_rules being used is a filter. So calling this normally with filter values, I would not expect it to raise a DIDNotFound, but in the specific circumstances how it is being instrumented in the REST endpoint, I would still expect the rest endpoint to raise that.

So what I would do is at a existence check for the scope:name in the REST call. Thus a get_did call before.

Hope that makes sense :-)

Martin

@alexanderrichards
Copy link
Contributor Author

alexanderrichards commented Nov 28, 2023

Hi @bari12, I understand. I can therefore put this check not in the core layer but either in the api layer (in api/rule.py::list_replication_rules) or REST layer (core/dids.py::Rules::get). Where would you say it makes most sense? Would you expect that the api layer raise DataIdentifierNotFound exception or only from REST?

@bari12
Copy link
Member

bari12 commented Nov 28, 2023

Yes, that's the two options I see as well.

My feeling is that this is a bit more accurate to be adressed in the REST layer directly. Thus in /dids/{scope_name}/rules you add the existence check of the did.

It's not entirely wrong to do it in api/rule.py::list_replication_rules either, but you would have to do something like check if only scope and name are in the filter, and if this is the case, then also check for did existence. But this feels a tiny bit assumptious to me, since you do not entirely know at that point that only a specific DID (which should exist) is being checked. At the REST layer you do know that, so I would put it there.

@alexanderrichards alexanderrichards force-pushed the patch-6334-Fix_listing_of_DID_rules_when_none_found_ branch from e0c3262 to 16bb6f9 Compare November 29, 2023 09:52
@alexanderrichards
Copy link
Contributor Author

looks like the changes are causing a test to fail because the mocked scope/name combination are clearly not found in the new get_did api call. How would you like to proceed? I can mock this call if you like.

[gw0] linux -- Python 3.9.18 /opt/venv/bin/python
tests/test_rule.py:1379: in test_list_rules_by_did
    ret = rucio_client.list_did_rules(scope=mock_scope.external, name=dataset['name'])
lib/rucio/client/didclient.py:544: in list_did_rules
    raise exc_cls(exc_msg)
E   rucio.common.exception.DataIdentifierNotFound: Data identifier not found.

@bari12
Copy link
Member

bari12 commented Nov 29, 2023

I think the problem here is that you need to add the VO into the get_did call as well. Similar to

did = get_did(scope=scope, name=name, dynamic_depth=dynamic_depth, vo=request.environ.get('vo'))

@alexanderrichards alexanderrichards force-pushed the patch-6334-Fix_listing_of_DID_rules_when_none_found_ branch from 764293d to d01b01f Compare November 29, 2023 15:07
@bari12 bari12 merged commit 1081588 into rucio:master Dec 18, 2023
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

List DID Rules will give 200 even if DID does not exist
2 participants