self = <swh.storage.tests.test_storage.TestStorage object at 0x7f46fc19d240>
swh_storage = <swh.storage.validate.ValidatingProxyStorage object at 0x7f466c0a95c0>
def test_origin_visit_upsert_new(self, swh_storage):
# given
> origin_url = swh_storage.origin_add_one(data.origin2)
.tox/py3/lib/python3.7/site-packages/swh/storage/tests/test_storage.py:1968:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/storage/validate.py:109: in origin_add_one
return self.storage.origin_add_one(origin)
.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/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:1199: in origin_add_one
origin_row = list(db.origin_get_by_url([origin.url], cur))[0]
.tox/py3/lib/python3.7/site-packages/swh/storage/db.py:884: in origin_get_by_url
yield from execute_values_generator(cur, query, ((url,) for url in origins))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cur = <cursor object at 0x7f478e6b1af0; closed: -1>
sql = b'SELECT origin.url FROM (VALUES %s) as t(url)\n LEFT JOIN origin ON t.url = origin.url\n '
argslist = <generator object Db.origin_get_by_url.<locals>.<genexpr> at 0x7f45ba3c47c8>
template = b'(%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 "origin" does not exist
E LINE 2: LEFT JOIN origin ON t.url = origin.url
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