From e8c50648582321e09640cbceb7e274bf6faab1e4 Mon Sep 17 00:00:00 2001 From: Alp Tezbasaran Date: Thu, 20 Jun 2024 11:12:37 -0400 Subject: [PATCH] Resolve Windows OS encoding bug --- src/gened/db.py | 4 ++-- src/gened/migrate.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gened/db.py b/src/gened/db.py index 1f1d87b..54a4d83 100644 --- a/src/gened/db.py +++ b/src/gened/db.py @@ -74,8 +74,8 @@ def init_db() -> None: db.executescript(f.read()) # App-specific schema in the app's package - with current_app.open_resource('schema.sql', 'r') as f: - db.executescript(f.read()) + with current_app.open_resource('schema.sql', 'rb') as f: + db.executescript(f.read().decode('utf-8')) # Mark all existing migrations as applied (since this is a fresh DB) for func in _on_init_db_callbacks: diff --git a/src/gened/migrate.py b/src/gened/migrate.py index 2086f0c..423068b 100644 --- a/src/gened/migrate.py +++ b/src/gened/migrate.py @@ -90,7 +90,7 @@ def _apply_migrations(migrations: Iterable[MigrationDict]) -> None: def _migration_info(resource: Traversable) -> MigrationDict: """Get info on a migration, provided as an importlib.resources resource.""" db = get_db() - with resources.as_file(resource) as path, path.open() as f: + with resources.as_file(resource) as path, path.open(encoding='utf-8') as f: name = path.name info: MigrationDict = { 'name': name,