From 09d92bfbac20b064471fe428c75a27cd7b6f964d Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Mon, 11 Feb 2019 09:45:07 -0800 Subject: [PATCH] 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 --- tests/unit/test_web.py | 6 ++++-- zuul/driver/sql/sqlconnection.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_web.py b/tests/unit/test_web.py index e267734958..c31633c150 100755 --- a/tests/unit/test_web.py +++ b/tests/unit/test_web.py @@ -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'}, ]) diff --git a/zuul/driver/sql/sqlconnection.py b/zuul/driver/sql/sqlconnection.py index 170dddf4a2..1a9f590526 100644 --- a/zuul/driver/sql/sqlconnection.py +++ b/zuul/driver/sql/sqlconnection.py @@ -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']