Skip to content

Commit

Permalink
Merge pull request #7652 from tdesveaux/tests/warnings/sqla-row-non-i…
Browse files Browse the repository at this point in the history
…nt-slice-indices

test: fix SQLAlchemy 'Using non-integer/slice indices on Row is deprecated'
  • Loading branch information
p12tic committed May 21, 2024
2 parents 3ed2538 + d5edc66 commit ebb7390
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
6 changes: 3 additions & 3 deletions master/buildbot/db/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def thd(conn) -> list[BuilderModel]:
rv: list[BuilderModel] = []
last: BuilderModel | None = None
for row in conn.execute(q).fetchall():
if not last or row['id'] != last.id:
if not last or row.id != last.id:
last = BuilderModel(
id=row.id,
name=row.name,
Expand All @@ -207,8 +207,8 @@ def thd(conn) -> list[BuilderModel]:
tags=bldr_id_to_tags[row.id],
)
rv.append(last)
if row['masterid']:
last.masterids.append(row['masterid'])
if row.masterid:
last.masterids.append(row.masterid)
return rv

return self.db.pool.do(thd)
8 changes: 4 additions & 4 deletions master/buildbot/db/migrate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def test_unicode(migrate_engine):

# see if the data is intact
row = migrate_engine.execute(test_unicode.select()).fetchall()[0]
assert isinstance(row['u'], str)
assert row['u'] == u
assert isinstance(row['b'], bytes)
assert row['b'] == b
assert isinstance(row.u, str)
assert row.u == u
assert isinstance(row.b, bytes)
assert row.b == b

# drop the test table
test_unicode.drop()
4 changes: 2 additions & 2 deletions master/buildbot/db/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ def thd(conn):
)
row = conn.execute(q).fetchone()
# ok, that was us, so we just do nothing
if row['masterid'] == masterid:
if row.masterid == masterid:
return None
raise SchedulerAlreadyClaimedError(f"already claimed by {row['name']}") from e
raise SchedulerAlreadyClaimedError(f"already claimed by {row.name}") from e
return None

return self.db.pool.do(thd)
Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/db/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def thd(conn) -> list[str]:
if result_spec is not None:
return result_spec.thd_execute(conn, q, lambda x: x['path'])
res = conn.execute(q)
return [row['path'] for row in res.fetchall()]
return [row.path for row in res.fetchall()]

return self.db.pool.do(thd)

Expand Down Expand Up @@ -192,9 +192,9 @@ def thd(conn) -> list[str]:
if name_prefix is not None:
q = q.where(names_table.c.name.startswith(name_prefix))
if result_spec is not None:
return result_spec.thd_execute(conn, q, lambda x: x['name'])
return result_spec.thd_execute(conn, q, lambda x: x.name)
res = conn.execute(q)
return [row['name'] for row in res.fetchall()]
return [row.name for row in res.fetchall()]

return self.db.pool.do(thd)

Expand Down
6 changes: 3 additions & 3 deletions master/buildbot/db/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def thd(conn):
q = sa.select(cfg_tbl.c.buildermasterid).select_from(j).distinct()
q = q.where(bm_tbl.c.masterid == masterid)
res = conn.execute(q)
buildermasterids = [row['buildermasterid'] for row in res]
buildermasterids = [row.buildermasterid for row in res]
res.close()
self._deleteFromConfiguredWorkers_thd(conn, buildermasterids)

Expand All @@ -141,7 +141,7 @@ def thd(conn):
q = q.where(bm_tbl.c.masterid == masterid)
q = q.where(bm_tbl.c.builderid.in_(builderids))
res = conn.execute(q)
buildermasterids = {row['id'] for row in res}
buildermasterids = {row.id for row in res}
res.close()
else:
buildermasterids = set([])
Expand All @@ -152,7 +152,7 @@ def thd(conn):
q = q.where(bm_tbl.c.masterid == masterid)
q = q.where(cfg_tbl.c.workerid == workerid)
res = conn.execute(q)
oldbuildermasterids = {row['buildermasterid'] for row in res}
oldbuildermasterids = {row.buildermasterid for row in res}
res.close()

todeletebuildermasterids = oldbuildermasterids - buildermasterids
Expand Down
5 changes: 0 additions & 5 deletions master/buildbot/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@
"The current statement is being autocommitted using implicit autocommit",
category=RemovedIn20Warning,
)
warnings.filterwarnings(
'ignore',
"Using non-integer/slice indices on Row is deprecated and will be removed in version 2.0",
category=RemovedIn20Warning,
)
warnings.filterwarnings(
'ignore',
"The ``bind`` argument for schema methods that invoke SQL against an engine or connection will be required in SQLAlchemy 2.0.",
Expand Down

0 comments on commit ebb7390

Please sign in to comment.