Fixes problems with extras for custom connection types (#13640)

The custom providers with custom connections can define
extra widgets and fields, however there were problems with
those custom fields in Aiflow 2.0.0:

* When connection type was a subset of another connection
  type (for example jdbc and jdbcx) widgets from the
  'subset' connection type appeared also in the 'superset'
  one due to prefix matching in javascript.

* Each connection when saved received 'full set' of extra
  fields from other connection types (with empty values).
  This problem is likely present in Airflow 1.10 but due
  to limited number of connections supported it had no
  real implications besides slightly bigger dictionary
  stored in 'extra' field.

* The extra field values were not saved for custom connections.
  Only the predefined connection types could save extras in
  extras field.

This PR fixes it by:

* adding __ matching for javascript to match only full connection
  types not prefixes
* saving only the fields matching extra__<conn_type> when the
  connection is saved
* removing filtering on 'known' connection types (the above
  filtering on `extra__` results in empty extra for
  connections that do not have any extra field defined.

Fixes #13597
This commit is contained in:
Jarek Potiuk 2021-01-13 00:32:49 +01:00 коммит произвёл GitHub
Родитель 34eb203c51
Коммит b007fc33d4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 8 добавлений и 4 удалений

Просмотреть файл

@ -31,7 +31,7 @@ $(document).ready(function () {
$.each($("[id^='extra__']"), function () { $.each($("[id^='extra__']"), function () {
$(this).parent().parent().addClass('hide') $(this).parent().parent().addClass('hide')
}); });
$.each($("[id^='extra__" + connectionType + "']"), function () { $.each($("[id^='extra__" + connectionType + "__']"), function () {
$(this).parent().parent().removeClass('hide') $(this).parent().parent().removeClass('hide')
}); });
$("label[orig_text]").each(function () { $("label[orig_text]").each(function () {

Просмотреть файл

@ -2894,9 +2894,13 @@ class ConnectionModelView(AirflowModelView):
def process_form(self, form, is_created): def process_form(self, form, is_created):
"""Process form data.""" """Process form data."""
formdata = form.data conn_type = form.data['conn_type']
if formdata['conn_type'] in ['jdbc', 'google_cloud_platform', 'grpc', 'yandexcloud', 'kubernetes']: extra = {
extra = {key: formdata[key] for key in self.extra_fields if key in formdata} key: form.data[key]
for key in self.extra_fields
if key in form.data and key.startswith(f"extra__{conn_type}__")
}
if extra.keys():
form.extra.data = json.dumps(extra) form.extra.data = json.dumps(extra)
def prefill_form(self, form, pk): def prefill_form(self, form, pk):