Skip to content

Connection support for repeated extra fields #9060

Closed

Description

@frnidito

Description

The Connection object should be able to support repeated keys in the extra fields.

Use case / motivation

Some connections strings, for instance the one used by MongoDB, support the repetition of keys such as in setting the rules for the precedence in choosing data-centres:

mongodb://mongos1.example.com,mongos2.example.com/?readPreference=secondary&readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=dc:ny&readPreferenceTags=

At the moment, there is no way to set this in the Connection neither though the UI nor using the CLI.

>>> from airflow.models.connection import Connection
>>> c = Connection(uri='my-conn-type://my-login:my-password@my-host:5432/my-schema?param1=val1&param2=val2')
>>> c.extra
'{"param1": "val1", "param2": "val2"}'
>>> c.set_extra('{"param1": "val1", "param1": "val2"}')  # <- here
>>> c.get_uri()
'my-conn-type://my-login:my-password@my-host:5432/my-schema?param1=val2'

Adding support to this, maybe with an array form in the JSON would be ideal, i.e., being able to write something like:

>>> c.set_extra('{"param1": ["val1", "val2"]}')
>>> c.get_uri()
'my-conn-type://my-login:my-password@my-host:5432/my-schema?param1=val1&param1=val2'

Activity

  1. boring-cyborg commented on May 29, 2020

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template!

  2. mik-laj commented on May 31, 2020

    @mik-laj
    Member

    self.extra = json.dumps(dict(parse_qsl(uri_parts.query, keep_blank_values=True)))

    If we want arrays to be created via the URL, we need to improve the parsing of the query string. Currently, you can only define a string there.

  3. dstandish commented on Apr 15, 2021

    @dstandish
    Contributor

    @frnidito we now can serialize full json to the conn URI (see #15100)

    is it ok to close this issue?

  4. github-actions commented on Jun 20, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 30 days with no response from the author. It will be closed in next 7 days if no further activity occurs from the issue author.

  5. added
    staleStale PRs per the .github/workflows/stale.yml policy file
    on Jun 20, 2021
  6. github-actions commented on Jun 28, 2021

    @github-actions
    Contributor

    This issue has been closed because it has not received response from the issue author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions