self = <swh.storage.tests.test_storage.TestStorage object at 0x7f45ba256208>
swh_storage = <swh.storage.validate.ValidatingProxyStorage object at 0x7f45ba2562b0>
def test_content_add_collision(self, swh_storage):
cont1 = data.cont
# create (corrupted) content with same sha1{,_git} but != sha256
cont1b = cont1.copy()
sha256_array = bytearray(cont1b["sha256"])
sha256_array[0] += 1
cont1b["sha256"] = bytes(sha256_array)
with pytest.raises(HashCollision) as cm:
> swh_storage.content_add([cont1, cont1b])
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:330:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:60: in content_add
return self.storage.content_add(contents)
.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/storage/storage.py:204: in content_add
cur=cur,
.tox/py3/lib/python3.7/site-packages/swh/core/db/common.py:90: in _meth
yield from meth(self, *args, **kwargs)
.tox/py3/lib/python3.7/site-packages/swh/storage/storage.py:329: in content_missing
for obj in db.content_missing_from_list(content, cur):
.tox/py3/lib/python3.7/site-packages/swh/storage/db.py:147: in content_missing_from_list
(tuple(c[key] for key in self.content_hash_keys) for c in contents),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cur = <cursor object at 0x7f478e6b1ce0; closed: -1>
sql = b'\n SELECT sha1, sha1_git, sha256, blake2s256\n FROM (VALUES %s) as t(sha1, sha1_git, sha256, b....sha1 AND t.sha1_git = c.sha1_git AND t.sha256 = c.sha256 AND t.blake2s256 = c.blake2s256\n )\n '
argslist = <generator object Db.content_missing_from_list.<locals>.<genexpr> at 0x7f45d469e408>
template = b'(%s,%s,%s,%s)', page_size = 100
def execute_values_generator(cur, sql, argslist, template=None, page_size=100):
"""Execute a statement using SQL ``VALUES`` with a sequence of parameters.
Rows returned by the query are returned through a generator.
You need to consume the generator for the queries to be executed!
:param cur: the cursor to use to execute the query.
:param sql: the query to execute. It must contain a single ``%s``
placeholder, which will be replaced by a `VALUES list`__.
Example: ``"INSERT INTO mytable (id, f1, f2) VALUES %s"``.
:param argslist: sequence of sequences or dictionaries with the arguments
to send to the query. The type and content must be consistent with
*template*.
:param template: the snippet to merge to every item in *argslist* to
compose the query.
- If the *argslist* items are sequences it should contain positional
placeholders (e.g. ``"(%s, %s, %s)"``, or ``"(%s, %s, 42)``" if there
are constants value...).
- If the *argslist* items are mappings it should contain named
placeholders (e.g. ``"(%(id)s, %(f1)s, 42)"``).
If not specified, assume the arguments are sequence and use a simple
positional template (i.e. ``(%s, %s, ...)``), with the number of
placeholders sniffed by the first element in *argslist*.
:param page_size: maximum number of *argslist* items to include in every
statement. If there are more items the function will execute more than
one statement.
:param yield_from_cur: Whether to yield results from the cursor in this
function directly.
.. __: https://www.postgresql.org/docs/current/static/queries-values.html
After the execution of the function the `cursor.rowcount` property will
**not** contain a total result.
"""
# we can't just use sql % vals because vals is bytes: if sql is bytes
# there will be some decoding error because of stupid codec used, and Py3
# doesn't implement % on bytes.
if not isinstance(sql, bytes):
sql = sql.encode(psycopg2.extensions.encodings[cur.connection.encoding])
pre, post = _split_sql(sql)
for page in _paginate(argslist, page_size=page_size):
if template is None:
template = b"(" + b",".join([b"%s"] * len(page[0])) + b")"
parts = pre[:]
for args in page:
parts.append(cur.mogrify(template, args))
parts.append(b",")
parts[-1:] = post
> cur.execute(b"".join(parts))
E psycopg2.errors.UndefinedTable: relation "content" does not exist
E LINE 5: SELECT 1 FROM content c
E ^
.tox/py3/lib/python3.7/site-packages/swh/core/db/db_utils.py:150: UndefinedTable
TEST RESULT
TEST RESULT
- Run At
- May 20 2020, 9:28 AM