Skip to content

Conversation

@Hasan-J
Copy link
Contributor

@Hasan-J Hasan-J commented May 29, 2020

Closes #8608

Added an alembic revision, if the user already has multiple records with the same conn_id
in the connections table, it throws an exception during airflow db upgrade with a clear
message.


Make sure to mark the boxes below before creating PR: [x]

  • Description above provides context of the change
  • Unit tests coverage for changes (not needed for documentation changes)
  • Target Github ISSUE in description if exists
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions.
  • I will engage committers as explained in Contribution Workflow Example.

In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

@boring-cyborg
Copy link

boring-cyborg bot commented May 29, 2020

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/master/CONTRIBUTING.rst)
Here are some useful points:

@feluelle feluelle self-requested a review May 30, 2020 07:20
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a note in UPDATING.md about this change. Also (but probably later) some migration tool for airflow 2.0 should also deal with this case if someone already has connection in their database . We will have to figure out migration scheme, but I think a note in UPDATING.md will be enough to remember about doing it.

@Hasan-J
Copy link
Contributor Author

Hasan-J commented Jun 1, 2020

I have removed the test method test_connection_metastore_secrets_backend in tests/secrets/test_secrets_backends.py based on the fact that it's using mutiple connections with the same conn_id. Maybe someone can confirm that this indeed should be removed !

@Hasan-J Hasan-J requested a review from potiuk June 1, 2020 16:47
@mik-laj
Copy link
Member

mik-laj commented Jun 8, 2020

I wonder if we should mark this field as non nullable.
Here is the master table:

                                          Table "public.connection"
       Column       |          Type           | Collation | Nullable |                Default
--------------------+-------------------------+-----------+----------+----------------------------------------
 id                 | integer                 |           | not null | nextval('connection_id_seq'::regclass)
 conn_id            | character varying(250)  |           |          |
 conn_type          | character varying(500)  |           |          |
 host               | character varying(500)  |           |          |
 schema             | character varying(500)  |           |          |
 login              | character varying(500)  |           |          |
 password           | character varying(5000) |           |          |
 port               | integer                 |           |          |
 extra              | character varying(5000) |           |          |
 is_encrypted       | boolean                 |           |          |
 is_extra_encrypted | boolean                 |           |          |
Indexes:
    "connection_pkey" PRIMARY KEY, btree (id)

conn_type should also not be empty, but that's another issue.

@mik-laj mik-laj mentioned this pull request Jun 8, 2020
6 tasks
@mik-laj
Copy link
Member

mik-laj commented Jun 9, 2020

Would it be a big problem to use this field as the primary key instead of just adding a second unique index? The primary key is also a unique index.

Copy link
Member

@ashb ashb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the airflow.secrets.local_filesystem needs updating too -- it still supports multiple connections with the same id.

@ashb ashb changed the title [AIRFLOW-8608] Make conn_id unique in Connections table Make conn_id unique in Connections table Jun 15, 2020
@ashb ashb removed the area:docs label Jun 15, 2020
@Hasan-J
Copy link
Contributor Author

Hasan-J commented Jun 16, 2020

I think the airflow.secrets.local_filesystem needs updating too -- it still supports multiple connections with the same id.

Oh, this is my first time reading about this backend. Should we stop and raise an exception in case of multiple connections or just load the last one specified ?

@mik-laj mik-laj added this to the Airflow 2.0.0 milestone Jun 21, 2020
@mik-laj
Copy link
Member

mik-laj commented Jun 21, 2020

@Hasan-J I think It would be a better idea to raise an exception.

@Hasan-J Hasan-J requested review from ashb and feluelle June 22, 2020 21:42
@mik-laj mik-laj self-requested a review June 25, 2020 13:19
@Hasan-J Hasan-J closed this Jun 29, 2020
@Hasan-J Hasan-J reopened this Jun 29, 2020
drdenzy pushed a commit to astronomer/airflow that referenced this pull request Jan 20, 2021
As written in apache#9067,
Airflow 2.0 introduces a change that requires that all Airflow
connections be unique (whereas Airflow 1.10.x
technically supports two connections with the same name and
potentially the same values).

With this commit, we show "warning" in the Airflow UI for users
with duplicate connections
kaxil added a commit to astronomer/airflow that referenced this pull request Mar 15, 2021
As written in apache#9067,
Airflow 2.0 introduces a change that requires that all Airflow
connections be unique (whereas Airflow 1.10.x
technically supports two connections with the same name and
potentially the same values).

With this commit, we show "warning" in the Airflow UI for users
with duplicate connections
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Sep 15, 2021
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Sep 17, 2021
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Sep 23, 2021
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Nov 27, 2021
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Mar 10, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Jun 4, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Jun 7, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Jul 9, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
@Hasan-J Hasan-J deleted the unique_conn_id branch August 15, 2022 14:17
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Aug 27, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Oct 4, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
aglipska pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Oct 7, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Dec 7, 2022
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Jan 27, 2023
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to kosteev/composer-airflow-test-copybara that referenced this pull request Sep 12, 2024
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to kosteev/composer-airflow-test-copybara that referenced this pull request Sep 12, 2024
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Sep 17, 2024
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Nov 7, 2024
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request May 1, 2025
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request May 21, 2025
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Sep 16, 2025
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this pull request Oct 15, 2025
apache/airflow#9067 made conn_id unique,
and this is effective from 2.0.*.
Due to this change, BaseHook.get_connections() will return a List of length 1, or raise Exception.

In such a case, we should simply always get the only element
from the result from BaseHook.get_connections(),
and drop random.choice() in BaseHook.get_connection(), which was only applicable for the earlier
setting (multiple connections is allowed for single conn_id)

GitOrigin-RevId: 74ed92b3ff34fa3b6af27c17f44ad4573b517bbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make conn_id unique in Connections table

7 participants