From 7ae94f414c9e24fea677c5f3721645ac69115f13 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Thu, 19 Nov 2015 12:58:06 -0500 Subject: [PATCH] Alias our subqueries to appease the MySQL beast --- data/model/storage.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/data/model/storage.py b/data/model/storage.py index ef983ecc9..10f4c9f6b 100644 --- a/data/model/storage.py +++ b/data/model/storage.py @@ -226,12 +226,14 @@ def lookup_repo_storages_by_content_checksum(repo, checksums): # to use a union to select just one storage with each checksum queries = [] - for checksum in set(checksums): + for counter, checksum in enumerate(set(checksums)): + query_alias = 'q{0}'.format(counter) candidate_subq = (ImageStorage .select(ImageStorage.id, ImageStorage.content_checksum) .join(Image) .where(Image.repository == repo, ImageStorage.content_checksum == checksum) - .limit(1)) + .limit(1) + .alias(query_alias)) queries.append(ImageStorage .select(SQL('*')) .from_(candidate_subq))