abhishekbhakat opened a new issue, #34332:
URL: https://github.com/apache/airflow/issues/34332
### Apache Airflow version
main (development)
### What happened
The SQL query generated does not have a default integer as 0 in the
migration causing failure.
```
INFO [alembic.runtime.migration] Running upgrade 405de8318b3a ->
375a816bbbf4, add new field 'clear_number' to dagrun
Traceback (most recent call last):
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/base.py",
line 1910, in _execute_context
self.dialect.do_execute(
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/default.py",
line 736, in do_execute
cursor.execute(statement, parameters)
psycopg2.errors.NotNullViolation: column "clear_number" of relation
"dag_run" contains null values
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/bin/airflow",
line 8, in <module>
sys.exit(main())
^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/__main__.py",
line 59, in main
args.func(args)
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/cli/cli_config.py",
line 49, in command
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/utils/cli.py",
line 114, in wrapper
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/utils/providers_configuration_loader.py",
line 55, in wrapped_function
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/cli/commands/db_command.py",
line 129, in migratedb
db.upgradedb(
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/utils/session.py",
line 79, in wrapper
return func(*args, session=session, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/utils/db.py",
line 1627, in upgradedb
command.upgrade(config, revision=to_revision or "heads")
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/command.py",
line 382, in upgrade
script.run_env()
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/script/base.py",
line 578, in run_env
util.load_python_file(self.dir, "env.py")
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/util/pyfiles.py",
line 93, in load_python_file
module = load_module_py(module_id, path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/util/pyfiles.py",
line 109, in load_module_py
spec.loader.exec_module(module) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in
_call_with_frames_removed
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/migrations/env.py",
line 117, in <module>
run_migrations_online()
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/migrations/env.py",
line 111, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/runtime/environment.py",
line 922, in run_migrations
self.get_context().run_migrations(**kw)
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/runtime/migration.py",
line 624, in run_migrations
step.migration_fn(**kw)
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/airflow/migrations/versions/0129_2_8_0_add_clear_number_to_dag_run.py",
line 41, in upgrade
with op.batch_alter_table("dag_run") as batch_op:
File
"/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py",
line 144, in __exit__
next(self.gen)
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/operations/base.py",
line 375, in batch_alter_table
impl.flush()
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/operations/batch.py",
line 113, in flush
fn(*arg, **kw)
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/ddl/impl.py",
line 322, in add_column
self._exec(base.AddColumn(table_name, column, schema=schema))
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/alembic/ddl/impl.py",
line 193, in _exec
return conn.execute( # type: ignore[call-overload]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/future/engine.py",
line 280, in execute
return self._execute_20(
^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/base.py",
line 1710, in _execute_20
return meth(self, args_10style, kwargs_10style, execution_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/sql/ddl.py",
line 80, in _execute_on_connection
return connection._execute_ddl(
^^^^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/base.py",
line 1477, in _execute_ddl
ret = self._execute_context(
^^^^^^^^^^^^^^^^^^^^^^
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/base.py",
line 1953, in _execute_context
self._handle_dbapi_exception(
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/base.py",
line 2134, in _handle_dbapi_exception
util.raise_(
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/util/compat.py",
line 211, in raise_
raise exception
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/base.py",
line 1910, in _execute_context
self.dialect.do_execute(
File
"/Users/abhishekbhakat/Codes/Turbine/my_local_airflow/airflowenv/lib/python3.11/site-packages/sqlalchemy/engine/default.py",
line 736, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.NotNullViolation) column
"clear_number" of relation "dag_run" contains null values
[SQL: ALTER TABLE dag_run ADD COLUMN clear_number INTEGER NOT NULL]
(Background on this error at: https://sqlalche.me/e/14/gkpj)
```
SQLAlchemy version was 1.4.49.
### What you think should happen instead
The query generated should be `ALTER TABLE dag_run ADD COLUMN clear_number
INTEGER NOT NULL DEFAULT 0;`
### How to reproduce
Upgraded from airflow 2.7.1 to main-branch and ran `airflow db migrate`
### Operating System
MacOS 13
### Versions of Apache Airflow Providers
Not applicable
### Deployment
Virtualenv installation
### Deployment details
_No response_
### Anything else
_No response_
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]