From c97587562093a19aef1187650d8d74cd808a3e7a Mon Sep 17 00:00:00 2001 From: Sebastian Bank Date: Thu, 30 Nov 2017 15:59:58 +0100 Subject: [PATCH] more explicit division between complementary delete conditions --- clld/db/schema_migrations/update_assoc_tables.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/clld/db/schema_migrations/update_assoc_tables.py b/clld/db/schema_migrations/update_assoc_tables.py index fa81e39a..e36ebc3e 100644 --- a/clld/db/schema_migrations/update_assoc_tables.py +++ b/clld/db/schema_migrations/update_assoc_tables.py @@ -64,14 +64,13 @@ def upgrade(dry=True, verbose=True): def delete_null_duplicates(tablename, columns, notnull, returning=sa.text('*')): assert columns table = sa.table(tablename, *map(sa.column, ['pk'] + columns)) - yield table.delete(bind=conn).where(sa.or_(table.c[n] == sa.null() for n in notnull))\ - .returning(returning) + any_null = sa.or_(table.c[n] == sa.null() for n in notnull) + yield table.delete(bind=conn).where(any_null).returning(returning) other = table.alias() - yield table.delete(bind=conn).where(sa.and_(table.c[n] != sa.null() for n in notnull))\ + yield table.delete(bind=conn).where(~any_null).returning(returning)\ .where(sa.exists() .where(sa.and_(table.c[c] == other.c[c] for c in columns)) - .where(table.c.pk > other.c.pk))\ - .returning(returning) + .where(table.c.pk > other.c.pk)) def print_rows(rows, verbose=verbose): if not verbose: