Snapshot can be null for a visit status.
Return none instead of a snapshot object in that case.
Resolves T4514
Differential D8426
Return none for missing snapshot in a visit status jayeshv on Sep 8 2022, 4:58 PM. Authored by
Details
Snapshot can be null for a visit status. Resolves T4514
Diff Detail
Event TimelineComment Actions Build is green Patch application report for D8426 (id=30380)Rebasing onto 467e0b7e28... Current branch diff-target is up to date. Changes applied before testcommit 4ba54d838fedaa2ec74fc3f8f30683c10b7545b0 Author: Jayesh Velayudhan <jayesh@softwareheritage.org> Date: Thu Sep 8 16:53:39 2022 +0200 Return sensible errors for missing snapshots in visit status Snapshot will be None for a visit status with status other then full. Return a sensible error when snapshot is requested from such types. Related to T4514 See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/158/ for more details. Comment Actions There is another issue here. Snapshot SWHID is a non nullable field in the schema. Comment Actions @vlorentz The right fix is to add a new visit status type to the schema like below. type VisitStatusPartial { status: String! date: DateTime! type: String } type VisitStatusFull { status: String! date: DateTime! type: String snapshot: Snapshot! } A null snapshot in VisitStatusFull will cause an object not found error. I think they should have been two different objects in the swh-model as well, the existing design is not really type friendly. Comment Actions Why have two different types, instead of making the snapshot field nullable, like this? type VisitStatus { status: String! date: DateTime! type: String snapshot: Snapshot } Comment Actions That is the existing system. I think it will be a bad idea to remove non-nullable fields from the Sanpshot object. Comment Actions I do not get the issue here, using the following changes on top of your diff, it works as expected: 13:40 $ git diff diff --git a/swh/graphql/resolvers/visit_status.py b/swh/graphql/resolvers/visit_status.py index c5d2fa7..672a617 100644 --- a/swh/graphql/resolvers/visit_status.py +++ b/swh/graphql/resolvers/visit_status.py @@ -21,7 +21,8 @@ class BaseVisitStatusNode(BaseNode): @property def snapshotSWHID(self): # To support the schema naming convention if self._node.snapshot is None: - raise ObjectNotFoundError("Snapshot is not available for this visit status") + # raise ObjectNotFoundError("Snapshot is not available for this visit status") + return None return CoreSWHID(object_type=ObjectType.SNAPSHOT, object_id=self._node.snapshot) diff --git a/swh/graphql/tests/functional/test_visit_status.py b/swh/graphql/tests/functional/test_visit_status.py index 9e5a876..6d84c56 100644 --- a/swh/graphql/tests/functional/test_visit_status.py +++ b/swh/graphql/tests/functional/test_visit_status.py @@ -67,8 +67,3 @@ def test_get_visit_missing_snapshot(client): "status": result_status.status, "type": result_status.type, } - assert len(err) == 1 - assert ( - err[0]["message"] - == "Object error: Snapshot is not available for this visit status" - ) Comment Actions I can't find what part of the standard disallows it, nor any mention one way or another outside the standard. Any pointer? Comment Actions > I do not get the issue here, using the following changes on top of your diff, it works as expected: > It will work as expected in the data part. But there will be an error associated, that we think is unnecessary. Comment Actions Could you write a snippet query to reproduce the error ? I still do not get what's wrong here. Comment Actions query origins { origins(first: 2) { nodes { url visits(first: 2) { nodes { id status(first: 2) { nodes { status snapshot { swhid } } } } } } } } run this in staging, you will get a weird error in the errors section. Comment Actions The SWHID is a non nullable scalar from interface MerkleNode that snapshot imeplements. This is not specific, but an error is mandatory in case there is a missing non-nullable field. The error happens only when SWHID or ID, both non-nullable, are requested from a snapshot query origins { origins(first: 1) { nodes { url visits(first: 1) { nodes { id status(first: 2) { nodes { status snapshot { branches(first: 1) { nodes { name { text } } } } } } } } } } } Comment Actions The section you linked mentions null values in Non-Null fields, but not of null values for objects with a Non-Null field. Are you sure this is disallowed by the standard, not "only" a bug in the GraphQL library we use? Comment Actions I think it is the right behavior. Let me test with another library to make sure. It gets confusing.The schema validation allows to return a null object with non-nullable fields :) Comment Actions @vlorentz I think the behavior is correct, but the error we report is not. read the block above this Comment Actions Sure, but in that example, the error is because for some reason, they could not get the value of name for an object that exists. The error in the example even reflects this, as it mentions "character with ID 1002". In our case, that object does not exist at all. Comment Actions Correct. In our case, SWHID is null and that will anyway make the snapshot null. But SWHID is null because snapshot is already null :). "errors": [ { "message": "Snapshot.swhid can not be fetched as the snapshot is null", "locations": [ { "line": 12, "column": 17 } ], "path": [ "origins", "nodes", 0, "visits", "nodes", 0, "status", "nodes", 0, "snapshot", "swhid" ], Comment Actions Build is green Patch application report for D8426 (id=30418)Rebasing onto 6e5d34e94d... Current branch diff-target is up to date. Changes applied before testcommit f34bcebcfd457dee3f980c4462018d20238669de Author: Jayesh Velayudhan <jayesh@softwareheritage.org> Date: Thu Sep 8 16:53:39 2022 +0200 Return sensible errors for missing snapshots in visit status Snapshot will be None for a visit status with status other then full. Return a sensible error when snapshot is requested from such types. Related to T4514 See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/165/ for more details. Comment Actions Ah, I see. But that we have a null SWHID is an implementation detail, because the SWHID is how the snapshot is retrieved. If it was any other field, we would not have an error. From the protocol's point of view, this implementation matter should not be visible.
There should not be an error at all, because it is a completely expected condition. Comment Actions Here is a way to do it: diff --git a/swh/graphql/resolvers/resolvers.py b/swh/graphql/resolvers/resolvers.py index 60992bb..1b0e93f 100644 --- a/swh/graphql/resolvers/resolvers.py +++ b/swh/graphql/resolvers/resolvers.py @@ -93,6 +93,8 @@ def snapshot_resolver( def visit_snapshot_resolver( obj, info: GraphQLResolveInfo, **kw ) -> rs.snapshot.VisitSnapshotNode: + if obj.snapshotSWHID is None: + return None resolver = get_node_resolver("visit-snapshot") return resolver(obj, info, **kw) diff --git a/swh/graphql/tests/functional/test_visit_status.py b/swh/graphql/tests/functional/test_visit_status.py index a250a9a..d83861a 100644 --- a/swh/graphql/tests/functional/test_visit_status.py +++ b/swh/graphql/tests/functional/test_visit_status.py @@ -28,7 +28,7 @@ def test_get_visit_status(client): visit.origin, visit.visit, ) - data, _ = get_query_response(client, query_str) + data, err = get_query_response(client, query_str) result_status = get_visit_status()[3] assert data["visit"]["status"]["nodes"][0] == { "date": result_status.date.isoformat(), @@ -36,6 +36,7 @@ def test_get_visit_status(client): "status": result_status.status, "type": result_status.type, } + assert err is None def test_get_visit_missing_snapshot(client): @@ -67,7 +68,4 @@ def test_get_visit_missing_snapshot(client): "status": result_status.status, "type": result_status.type, } - assert len(err) == 1 - assert ( - "Cannot return null for non-nullable field Snapshot.swhid" in err[0]["message"] - ) + assert err is None Comment Actions Build is green Patch application report for D8426 (id=30424)Rebasing onto 6e5d34e94d... Current branch diff-target is up to date. Changes applied before testcommit 9b8c73df54d4b7bfe7df3d1f795dcd96ceba7857 Author: Jayesh Velayudhan <jayesh@softwareheritage.org> Date: Thu Sep 8 16:53:39 2022 +0200 Return sensible errors for missing snapshots in visit status Snapshot will be None for a visit status with status other then full. Return a sensible error when snapshot is requested from such types. Related to T4514 See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/166/ for more details. Comment Actions Build is green Patch application report for D8426 (id=30425)Rebasing onto 6e5d34e94d... Current branch diff-target is up to date. Changes applied before testcommit 39c64ad55702142f90220f6254259f06d2fe948c Author: Jayesh Velayudhan <jayesh@softwareheritage.org> Date: Thu Sep 8 16:53:39 2022 +0200 Return none for missing snapshot in a visit status Snapshot can be null for a visit status. Return none instead of a snapshot object in that case. Resolves T4514 See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/167/ for more details.
Comment Actions Build is green Patch application report for D8426 (id=30434)Rebasing onto 6e5d34e94d... Current branch diff-target is up to date. Changes applied before testcommit e2f9e03f3b242c6f22e3596432742876920d3434 Author: Jayesh Velayudhan <jayesh@softwareheritage.org> Date: Thu Sep 8 16:53:39 2022 +0200 Return none for missing snapshot in a visit status Snapshot can be null for a visit status. Return none instead of a snapshot object in that case. Resolves T4514 See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/168/ for more details.
Comment Actions Build is green Patch application report for D8426 (id=30450)Rebasing onto 6e5d34e94d... Current branch diff-target is up to date. Changes applied before testcommit 2c3b16f7952be753ac80f115619109e2c41a514b Author: Jayesh Velayudhan <jayesh@softwareheritage.org> Date: Thu Sep 8 16:53:39 2022 +0200 Return none for missing snapshot in a visit status Snapshot can be null for a visit status. Return none instead of a snapshot object in that case. Resolves T4514 See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/171/ for more details. |