From 79913af28a7a68eb98725df3343ccdcbe86a30fa Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Thu, 8 May 2025 20:20:27 -0700 Subject: [PATCH] Handle different SQLite version error messages Refs https://github.com/simonw/sqlite-utils/pull/653#issuecomment-2864967364 --- sqlite_utils/cli.py | 4 +++- tests/test_cli.py | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py index 795e30d..a19ee43 100644 --- a/sqlite_utils/cli.py +++ b/sqlite_utils/cli.py @@ -1098,7 +1098,9 @@ def insert_upsert_implementation( if ( isinstance(e, OperationalError) and e.args - and "has no column named" in e.args[0] + and ( + "has no column named" in e.args[0] or "no such column" in e.args[0] + ) ): raise click.ClickException( "{}\n\nTry using --alter to add additional columns".format( diff --git a/tests/test_cli.py b/tests/test_cli.py index 88763ee..17e5ed6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1116,10 +1116,8 @@ def test_upsert_alter(db_path, tmpdir): cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id"] ) assert result.exit_code == 1 - assert ( - "Error: table dogs has no column named age\n\n" - "Try using --alter to add additional columns" - ) == result.output.strip() + # Could be one of two errors depending on SQLite version + assert ("Try using --alter to add additional columns") in result.output.strip() # Should succeed with --alter result = CliRunner().invoke( cli.cli, ["upsert", db_path, "dogs", json_path, "--pk", "id", "--alter"]