1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-13 21:52:18 +00:00

Avoid Pony/MySQL problem

MySQL throws the following with bulk deletes. Non-bulk deletes don't generate complex SQL statements, so avoid the problem.

pony.orm.dbapiprovider.OperationalError: (1093, "Table 'self' is specified twice, both as a target for 'DELETE' and as a separate source for data")
This commit is contained in:
Jonathan Perry-Houts 2018-05-15 10:36:38 -07:00 committed by GitHub
parent fd21ae41df
commit a11a02429b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,7 +107,7 @@ class Folder(PathMixin, db.Entity):
not exists(f for f in Folder if f.parent == self) and not self.root) not exists(f for f in Folder if f.parent == self) and not self.root)
total = 0 total = 0
while True: while True:
count = query.delete(bulk = True) count = query.delete(bulk = False)
total += count total += count
if not count: if not count:
return total return total
@ -140,7 +140,7 @@ class Artist(db.Entity):
@classmethod @classmethod
def prune(cls): def prune(cls):
return cls.select(lambda self: not exists(a for a in Album if a.artist == self) and \ return cls.select(lambda self: not exists(a for a in Album if a.artist == self) and \
not exists(t for t in Track if t.artist == self)).delete(bulk = True) not exists(t for t in Track if t.artist == self)).delete(bulk = False)
class Album(db.Entity): class Album(db.Entity):
_table_ = 'album' _table_ = 'album'
@ -180,7 +180,7 @@ class Album(db.Entity):
@classmethod @classmethod
def prune(cls): def prune(cls):
return cls.select(lambda self: not exists(t for t in Track if t.album == self)).delete(bulk = True) return cls.select(lambda self: not exists(t for t in Track if t.album == self)).delete(bulk = False)
class Track(PathMixin, db.Entity): class Track(PathMixin, db.Entity):
_table_ = 'track' _table_ = 'track'