apache / apache/airflow

Custom validations are not called in connection forms

Open
#64,835 6 comments 0 reactions 0 assignees View on GitHub
area:UI kind:bug
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 7h
Merged PRs (30d)
484

Description

### Under which category would you file this issue?

Airflow Core

### Apache Airflow version

3.2.0

### What happened and how to reproduce it?

In airflow 3.2.0, defining custom validation for connection form doesn't work correctly. Validation is not called

as a example :
```python
@classmethod
def get_connection_form_widgets(cls) -> dict[str, Any]:
"""Return connection widgets to add to connection form."""
from flask_appbuilder.fieldwidgets import BS3TextFieldWidget
from flask_babel import lazy_gettext
from flask import flash
from wtforms.validators import Optional, ValidationError

def validate_cms_authentication(form, field):
valid = {"secEnterprise", "secLDAP", "secWinAD", "secSAPR3"}
if field.data and field.data not in valid:
flash("valeur non valide", "error")
raise ValidationError(
"Valeur invalide. Choisir parmi : secEnterprise, secLDAP, secWinAD, secSAPR3"
)
from wtforms import StringField

return {
"cms_system": StringField(
lazy_gettext("Système"), widget=BS3TextFieldWidget()
),
"cms_authentication": StringField(
lazy_gettext("Authentification"),
description="Méthode d'authentication (secEnterprise, secLDAP, secWinAD, secSAPR3)",
widget=BS3TextFieldWidget(),
default="secEnterprise",
validators=[Optional(), validate_cms_authentication],
),
}
```
when saving this:
Image

it is saved without error, I tried to add logging to check if validate_cms_authentication was called but no trace in log so I suppose that validation is not called

### What you think should happen instead?

Validation error messages should be displayed

### Operating System

_No response_

### Deployment

None

### Apache Airflow Provider(s)

_No response_

### Versions of Apache Airflow Providers

_No response_

### Official Helm Chart version

Not Applicable

### Kubernetes Version

_No response_

### Helm Chart configuration

_No response_

### Docker Image customizations

_No response_

### Anything else?

_No response_

### Are you willing to submit PR?

- [ ] 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)

Contributor guide

Open the contributing guide

Research direction

Start from the connection form handling in Airflow 3.2.0 and trace how the validators returned by get_connection_form_widgets are applied when the form is saved. Reproduce the cms_authentication example with an invalid value; done when the ValidationError message is displayed and valid values continue to save.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
56/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.