``` lang=python @pytest.mark.parametrize( "value", [pytest.param("foo", id="str"), pytest.param(1, id="int")] ) def test_revision_add_non_bytes_headers(self, swh_storage, value): extra_headers = [["foo", b"baz"], ["foo", value]] swh_storage.revision_add( [{**data.revision, "metadata": {"extra_headers": extra_headers}}] ) (r,) = swh_storage.revision_get([data.revision["id"]]) assert r["metadata"]["extra_headers"] == extra_headers ``` output: ``` .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_api_client.py::TestStorage::test_revision_add_non_bytes_headers[str] PASSED [ 12%] .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_api_client.py::TestStorage::test_revision_add_non_bytes_headers[int] PASSED [ 25%] .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_cassandra.py::TestCassandraStorage::test_revision_add_non_bytes_headers[str] FAILED [ 37%] .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_cassandra.py::TestCassandraStorage::test_revision_add_non_bytes_headers[int] FAILED [ 50%] .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_in_memory.py::TestStorage::test_revision_add_non_bytes_headers[str] PASSED [ 62%] .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_in_memory.py::TestStorage::test_revision_add_non_bytes_headers[int] PASSED [ 75%] .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py::TestStorage::test_revision_add_non_bytes_headers[str] FAILED [ 87%] .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py::TestStorage::test_revision_add_non_bytes_headers[int] FAILED [100%] =================================================================================================================================== FAILURES =================================================================================================================================== ________________________________________________________________________________________________________ TestCassandraStorage.test_revision_add_non_bytes_headers[str] _________________________________________________________________________________________________________ self = , swh_storage = , value = 'foo' @pytest.mark.parametrize( "value", [pytest.param("foo", id="str"), pytest.param(1, id="int")] ) def test_revision_add_non_bytes_headers(self, swh_storage, value): extra_headers = [["foo", b"baz"], ["foo", value]] swh_storage.revision_add( > [{**data.revision, "metadata": {"extra_headers": extra_headers}}] ) .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add [dict_converter(Revision, r) for r in revisions] .tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/storage.py:431: in revision_add revobject = revision_to_db(revision) .tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/converters.py:38: in revision_to_db metadata["extra_headers"] .tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db ret.append([key, decode_with_escape(values)]) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ value = 'foo' def decode_with_escape(value): """Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences as \\x. We also escape NUL bytes as they are invalid in JSON strings. """ # escape backslashes > value = value.replace(b"\\", b"\\\\") E TypeError: replace() argument 1 must be str, not bytes .tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: TypeError ------------------------------------------------------------------------------------------------------------------------------ Captured log setup ------------------------------------------------------------------------------------------------------------------------------ WARNING cassandra.cluster:cql.py:67 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version WARNING cassandra.cluster:cql.py:67 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version ---------------------------------------------------------------------------------------------------------------------------- Captured log teardown ----------------------------------------------------------------------------------------------------------------------------- WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version ________________________________________________________________________________________________________ TestCassandraStorage.test_revision_add_non_bytes_headers[int] _________________________________________________________________________________________________________ self = , swh_storage = , value = 1 @pytest.mark.parametrize( "value", [pytest.param("foo", id="str"), pytest.param(1, id="int")] ) def test_revision_add_non_bytes_headers(self, swh_storage, value): extra_headers = [["foo", b"baz"], ["foo", value]] swh_storage.revision_add( > [{**data.revision, "metadata": {"extra_headers": extra_headers}}] ) .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add [dict_converter(Revision, r) for r in revisions] .tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/storage.py:431: in revision_add revobject = revision_to_db(revision) .tox/py3/lib/python3.7/site-packages/swh/storage/cassandra/converters.py:38: in revision_to_db metadata["extra_headers"] .tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db ret.append([key, decode_with_escape(values)]) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ value = 1 def decode_with_escape(value): """Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences as \\x. We also escape NUL bytes as they are invalid in JSON strings. """ # escape backslashes > value = value.replace(b"\\", b"\\\\") E AttributeError: 'int' object has no attribute 'replace' .tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: AttributeError ------------------------------------------------------------------------------------------------------------------------------ Captured log setup ------------------------------------------------------------------------------------------------------------------------------ WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version ---------------------------------------------------------------------------------------------------------------------------- Captured log teardown ----------------------------------------------------------------------------------------------------------------------------- WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 66 to 65 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version WARNING cassandra.cluster:cql.py:134 Downgrading core protocol version from 65 to 4 for 127.0.0.1:55629. To avoid this, it is best practice to explicitly set Cluster(protocol_version) to the version supported by your cluster. http://datastax.github.io/python-driver/api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version _____________________________________________________________________________________________________________ TestStorage.test_revision_add_non_bytes_headers[str] _____________________________________________________________________________________________________________ self = , swh_storage = , value = 'foo' @pytest.mark.parametrize( "value", [pytest.param("foo", id="str"), pytest.param(1, id="int")] ) def test_revision_add_non_bytes_headers(self, swh_storage, value): extra_headers = [["foo", b"baz"], ["foo", value]] swh_storage.revision_add( > [{**data.revision, "metadata": {"extra_headers": extra_headers}}] ) .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add [dict_converter(Revision, r) for r in revisions] .tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:24: in d return f(*a, **kw) .tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:77: in d r = f(*a, **kw) .tox/py3/lib/python3.7/site-packages/swh/core/db/common.py:62: in _meth return meth(self, *args, db=db, cur=cur, **kwargs) .tox/py3/lib/python3.7/site-packages/swh/storage/storage.py:564: in revision_add revisions_filtered = list(map(converters.revision_to_db, revisions_filtered)) .tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:175: in revision_to_db extra_headers = git_headers_to_db(metadata["extra_headers"]) .tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db ret.append([key, decode_with_escape(values)]) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ value = 'foo' def decode_with_escape(value): """Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences as \\x. We also escape NUL bytes as they are invalid in JSON strings. """ # escape backslashes > value = value.replace(b"\\", b"\\\\") E TypeError: replace() argument 1 must be str, not bytes .tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: TypeError _____________________________________________________________________________________________________________ TestStorage.test_revision_add_non_bytes_headers[int] _____________________________________________________________________________________________________________ self = , swh_storage = , value = 1 @pytest.mark.parametrize( "value", [pytest.param("foo", id="str"), pytest.param(1, id="int")] ) def test_revision_add_non_bytes_headers(self, swh_storage, value): extra_headers = [["foo", b"baz"], ["foo", value]] swh_storage.revision_add( > [{**data.revision, "metadata": {"extra_headers": extra_headers}}] ) .tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1145: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:102: in revision_add [dict_converter(Revision, r) for r in revisions] .tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:24: in d return f(*a, **kw) .tox/py3/lib/python3.7/site-packages/swh/storage/metrics.py:77: in d r = f(*a, **kw) .tox/py3/lib/python3.7/site-packages/swh/core/db/common.py:62: in _meth return meth(self, *args, db=db, cur=cur, **kwargs) .tox/py3/lib/python3.7/site-packages/swh/storage/storage.py:564: in revision_add revisions_filtered = list(map(converters.revision_to_db, revisions_filtered)) .tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:175: in revision_to_db extra_headers = git_headers_to_db(metadata["extra_headers"]) .tox/py3/lib/python3.7/site-packages/swh/storage/converters.py:79: in git_headers_to_db ret.append([key, decode_with_escape(values)]) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ value = 1 def decode_with_escape(value): """Decode a bytestring as utf-8, escaping the bytes of invalid utf-8 sequences as \\x. We also escape NUL bytes as they are invalid in JSON strings. """ # escape backslashes > value = value.replace(b"\\", b"\\\\") E AttributeError: 'int' object has no attribute 'replace' .tox/py3/lib/python3.7/site-packages/swh/core/utils.py:101: AttributeError ```