Commit a9f60800 authored by Glandos's avatar Glandos
Browse files


parent ec316632
...@@ -393,7 +393,9 @@ class PostgreSQL(Database): ...@@ -393,7 +393,9 @@ class PostgreSQL(Database):
except psycopg2.DataError as error: except psycopg2.DataError as error:
if error.pgcode == psycopg2.errorcodes.CHARACTER_NOT_IN_REPERTOIRE: if error.pgcode == psycopg2.errorcodes.CHARACTER_NOT_IN_REPERTOIRE:
self.cursor.execute("ROLLBACK TO copy_files") self.cursor.execute("ROLLBACK TO copy_files")
self.copy_manager.threading_copy(self.get_source_files(torrent_ids, True)) self.copy_manager.threading_copy(
self.get_source_files(torrent_ids, True)
else: else:
raise raise
...@@ -444,13 +446,15 @@ class PostgreSQL(Database): ...@@ -444,13 +446,15 @@ class PostgreSQL(Database):
return select_cursor return select_cursor
def fix_bytes(self, rows: List[dict], column: str): def fix_bytes(self, rows: List[dict], column: str):
click.secho(f"Fix bytes value from {len(rows)} rows in column {column}", fg="yellow") click.secho(
f"Fix bytes value from {len(rows)} rows in column {column}", fg="yellow"
# Make a dict copy to be able to modify it # Make a dict copy to be able to modify it
rows = [dict(row) for row in rows] rows = [dict(row) for row in rows]
for row in rows: for row in rows:
old = row[column] old = row[column]
if isinstance(old, bytes): if isinstance(old, bytes):
old = old.decode('utf8', errors='replace') old = old.decode("utf8", errors="replace")
row[column] = old.replace("\x00", "") row[column] = old.replace("\x00", "")
return rows return rows
...@@ -502,6 +506,7 @@ def main(main_db, merged_db, fast): ...@@ -502,6 +506,7 @@ def main(main_db, merged_db, fast):
click.secho(f"Error while importing {str(e)}", fg="red") click.secho(f"Error while importing {str(e)}", fg="red")
target.connection.rollback() target.connection.rollback()
import traceback import traceback
traceback.print_exc() traceback.print_exc()
finally: finally:
target.after_import() target.after_import()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment