Add a note about sqlalchemy metadata

It's not obvious why we're renaming the attribute here.  Leave a
clue for later explorers.

Also, make test_artifacts handle artifacts being returned in a
different order.

Change-Id: Iffa216105f7e4951ea57fc073dacaa4040f82040
This commit is contained in:
James E. Blair 2019-02-11 09:45:07 -08:00
parent f12453f6cb
commit 09d92bfbac
2 changed files with 9 additions and 2 deletions

View File

@ -733,11 +733,13 @@ class TestArtifacts(ZuulDBTestCase, BaseTestWeb, AnsibleZuulTestCase):
"job_name=project-test1").json()
self.assertEqual(len(build_query), 1)
self.assertEqual(len(build_query[0]['artifacts']), 3)
arts = build_query[0]['artifacts']
arts.sort(key=lambda x: x['name'])
self.assertEqual(build_query[0]['artifacts'], [
{'url': 'http://example.com/tarball',
'name': 'tarball'},
{'url': 'http://example.com/docs',
'name': 'docs'},
{'url': 'http://logs.example.com/build/relative/docs',
'name': 'relative'},
{'url': 'http://example.com/tarball',
'name': 'tarball'},
])

View File

@ -223,6 +223,11 @@ class SQLConnection(BaseConnection):
def createArtifact(self, *args, **kw):
session = orm.session.Session.object_session(self)
# SQLAlchemy reserves the 'metadata' attribute on
# object models, so our model and table names use
# 'meta', but here we accept data directly from
# zuul_return where it's called 'metadata'. Transform
# the attribute name.
if 'metadata' in kw:
kw['meta'] = kw['metadata']
del kw['metadata']