You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ohaibbq (via GitHub)" <gi...@apache.org> on 2023/07/20 23:29:07 UTC
[GitHub] [airflow] ohaibbq opened a new pull request, #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
ohaibbq opened a new pull request, #32731:
URL: https://github.com/apache/airflow/pull/32731
We are utilizing the new `dag.test()` functionality with a Postgres-backed SQLAlchemy engine/session. We use the `airflow.utils.initdb()` and `airflow.utils.resetdb()` functions for test case setup/teardown.
When the schema is created for the second time, these event listeners add duplicate indexes to the SQLAlchemy `Table` definition, which causes the `metadata.create_all()` function to fail with a `DatabaseError` as it issues multiple `CREATE UNIQUE INDEX` statements for `idx_ab_user_username` and `idx_ab_register_user_username`.
This updates the listeners to check if the indexes have already been added before adding them to the `Table` definition.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on PR #32731:
URL: https://github.com/apache/airflow/pull/32731#issuecomment-1646984976
Please fix the static check failures. (I think other failures are unrelated)
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] ohaibbq commented on pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "ohaibbq (via GitHub)" <gi...@apache.org>.
ohaibbq commented on PR #32731:
URL: https://github.com/apache/airflow/pull/32731#issuecomment-1676694633
@eladkal Rebased! Thanks!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk merged pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #32731:
URL: https://github.com/apache/airflow/pull/32731
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #32731:
URL: https://github.com/apache/airflow/pull/32731#issuecomment-1644783906
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
Here are some useful points:
- Pay attention to the quality of your code (ruff, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
- In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
- Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
- Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
- Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
- Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
Apache Airflow is a community-driven project and together we are making it better 🚀.
In case of doubts contact the developers at:
Mailing List: dev@airflow.apache.org
Slack: https://s.apache.org/airflow-slack
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] ohaibbq commented on pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "ohaibbq (via GitHub)" <gi...@apache.org>.
ohaibbq commented on PR #32731:
URL: https://github.com/apache/airflow/pull/32731#issuecomment-1645968482
Hi @uranusjr, thanks for the review!
I wanted to add some context to this error while I have some eyes on the issue. We're manually configuring the engine in test via `AIRFLOW__DATABASE_SQL_ALCHEMY_CONN` and `settings.initialize()`.
This step seems superfluous as `dag.test` is supposed to accept a `session` (#29803), however, I was running into an error where a `TaskInstance` was not found since it `TaskInstance._run_raw_task` did not pass the session to `get_template_context`. Is this a known issue?
https://github.com/apache/airflow/blob/main/airflow/models/taskinstance.py#L1499
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] eladkal commented on pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "eladkal (via GitHub)" <gi...@apache.org>.
eladkal commented on PR #32731:
URL: https://github.com/apache/airflow/pull/32731#issuecomment-1667388542
@ohaibbq can you resolve conflicts and rebase?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] uranusjr commented on a diff in pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #32731:
URL: https://github.com/apache/airflow/pull/32731#discussion_r1270438362
##########
tests/www/fab_security/sqla/test_models.py:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from unittest import mock
+
+from airflow.www.fab_security.sqla.models import (
+ add_index_on_ab_user_username_postgres,
+ add_index_on_ab_register_user_username_postgres
+)
+
+from sqlalchemy import Table, Column, MetaData, String, create_mock_engine
+
+_mock_conn = mock.MagicMock()
+_mock_conn.dialect = mock.MagicMock()
+_mock_conn.dialect.name = "postgresql"
+
+
+def test_add_index_on_ab_user_username_postgres():
+ table = Table('test_table', MetaData(), Column("username", String))
Review Comment:
Add an assert here to ensure there’s no index yet?
##########
tests/www/fab_security/sqla/test_models.py:
##########
@@ -0,0 +1,56 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from unittest import mock
+
+from airflow.www.fab_security.sqla.models import (
+ add_index_on_ab_user_username_postgres,
+ add_index_on_ab_register_user_username_postgres
+)
+
+from sqlalchemy import Table, Column, MetaData, String, create_mock_engine
+
+_mock_conn = mock.MagicMock()
+_mock_conn.dialect = mock.MagicMock()
+_mock_conn.dialect.name = "postgresql"
+
+
+def test_add_index_on_ab_user_username_postgres():
+ table = Table('test_table', MetaData(), Column("username", String))
Review Comment:
Add an assert here to ensure there’s no index yet?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #32731: [Models] [Postgres] Check if the dynamically-added index is in the table schema before adding
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #32731:
URL: https://github.com/apache/airflow/pull/32731#issuecomment-1677102089
Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org