Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine Lambert
swh-core
Commits
e6497914
Commit
e6497914
authored
2 years ago
by
vlorentz
Browse files
Options
Downloads
Patches
Plain Diff
Remove support for deprecated exception format
It was removed from all RPC servers years ago.
parent
2d1cd6af
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swh/core/api/__init__.py
+13
-32
13 additions, 32 deletions
swh/core/api/__init__.py
swh/core/api/tests/test_rpc_client.py
+5
-20
5 additions, 20 deletions
swh/core/api/tests/test_rpc_client.py
with
18 additions
and
52 deletions
swh/core/api/__init__.py
+
13
−
32
View file @
e6497914
# Copyright (C) 2015-202
0
The Software Heritage developers
# Copyright (C) 2015-202
2
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
...
...
@@ -7,7 +7,6 @@ from collections import abc
import
functools
import
inspect
import
logging
import
pickle
from
typing
import
(
Any
,
Callable
,
...
...
@@ -325,36 +324,18 @@ class RPCClient(metaclass=MetaRPCClient):
exception
=
None
# TODO: only old servers send pickled error; stop trying to unpickle
# after they are all upgraded
try
:
if
status_class
==
4
:
data
=
self
.
_decode_response
(
response
,
check_status
=
False
)
if
isinstance
(
data
,
dict
):
# TODO: remove "exception" key check once all servers
# are using new schema
exc_data
=
data
[
"
exception
"
]
if
"
exception
"
in
data
else
data
for
exc_type
in
self
.
reraise_exceptions
:
if
exc_type
.
__name__
==
exc_data
[
"
type
"
]:
exception
=
exc_type
(
*
exc_data
[
"
args
"
])
break
else
:
exception
=
RemoteException
(
payload
=
exc_data
,
response
=
response
)
else
:
exception
=
pickle
.
loads
(
data
)
elif
status_class
==
5
:
data
=
self
.
_decode_response
(
response
,
check_status
=
False
)
if
"
exception_pickled
"
in
data
:
exception
=
pickle
.
loads
(
data
[
"
exception_pickled
"
])
else
:
# TODO: remove "exception" key check once all servers
# are using new schema
exc_data
=
data
[
"
exception
"
]
if
"
exception
"
in
data
else
data
exception
=
RemoteException
(
payload
=
exc_data
,
response
=
response
)
except
(
TypeError
,
pickle
.
UnpicklingError
):
raise
RemoteException
(
payload
=
data
,
response
=
response
)
if
status_class
==
4
:
exc_data
=
self
.
_decode_response
(
response
,
check_status
=
False
)
for
exc_type
in
self
.
reraise_exceptions
:
if
exc_type
.
__name__
==
exc_data
[
"
type
"
]:
exception
=
exc_type
(
*
exc_data
[
"
args
"
])
break
else
:
exception
=
RemoteException
(
payload
=
exc_data
,
response
=
response
)
elif
status_class
==
5
:
exc_data
=
self
.
_decode_response
(
response
,
check_status
=
False
)
exception
=
RemoteException
(
payload
=
exc_data
,
response
=
response
)
if
exception
:
raise
exception
from
None
...
...
This diff is collapsed.
Click to expand it.
swh/core/api/tests/test_rpc_client.py
+
5
−
20
View file @
e6497914
# Copyright (C) 2018-20
19
The Software Heritage developers
# Copyright (C) 2018-20
22
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
...
...
@@ -110,13 +110,11 @@ def test_client_connexion_error(rpc_client, requests_mock):
assert
str
(
exc_info
.
value
.
args
[
0
])
==
error_message
def
_exception_response
(
exception
,
status_code
,
old_exception_schema
=
False
):
def
_exception_response
(
exception
,
status_code
):
def
callback
(
request
,
context
):
assert
request
.
headers
[
"
Content-Type
"
]
==
"
application/x-msgpack
"
context
.
headers
[
"
Content-Type
"
]
=
"
application/x-msgpack
"
exc_dict
=
exception_to_dict
(
exception
)
if
old_exception_schema
:
exc_dict
=
{
"
exception
"
:
exc_dict
}
context
.
content
=
msgpack_dumps
(
exc_dict
)
context
.
status_code
=
status_code
return
context
.
content
...
...
@@ -124,8 +122,7 @@ def _exception_response(exception, status_code, old_exception_schema=False):
return
callback
@pytest.mark.parametrize
(
"
old_exception_schema
"
,
[
False
,
True
])
def
test_client_reraise_exception
(
rpc_client
,
requests_mock
,
old_exception_schema
):
def
test_client_reraise_exception
(
rpc_client
,
requests_mock
):
"""
Exception caught server-side and whitelisted will be raised again client-side.
"""
...
...
@@ -137,7 +134,6 @@ def test_client_reraise_exception(rpc_client, requests_mock, old_exception_schem
content
=
_exception_response
(
exception
=
ReraiseException
(
error_message
),
status_code
=
400
,
old_exception_schema
=
old_exception_schema
,
),
)
...
...
@@ -147,18 +143,8 @@ def test_client_reraise_exception(rpc_client, requests_mock, old_exception_schem
assert
str
(
exc_info
.
value
)
==
error_message
@pytest.mark.parametrize
(
"
status_code, old_exception_schema
"
,
[
(
400
,
False
),
(
500
,
False
),
(
400
,
True
),
(
500
,
True
),
],
)
def
test_client_raise_remote_exception
(
rpc_client
,
requests_mock
,
status_code
,
old_exception_schema
):
@pytest.mark.parametrize
(
"
status_code
"
,
[
400
,
500
])
def
test_client_raise_remote_exception
(
rpc_client
,
requests_mock
,
status_code
):
"""
Exception caught server-side and not whitelisted will be wrapped and raised
as a RemoteException client-side.
...
...
@@ -171,7 +157,6 @@ def test_client_raise_remote_exception(
content
=
_exception_response
(
exception
=
Exception
(
error_message
),
status_code
=
status_code
,
old_exception_schema
=
old_exception_schema
,
),
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment