Skip to content

Commit

Permalink
Print the key name when max_length is exceeded (#43061)
Browse files Browse the repository at this point in the history
* Print the key name when max_length is exceeded

* Fix tests
  • Loading branch information
jabbera authored Oct 17, 2024
1 parent f587edf commit 3f8ac22
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion airflow/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def validate_key(k: str, max_length: int = 250):
if not isinstance(k, str):
raise TypeError(f"The key has to be a string and is {type(k)}:{k}")
if len(k) > max_length:
raise AirflowException(f"The key has to be less than {max_length} characters")
raise AirflowException(f"The key: {k} has to be less than {max_length} characters")
if not KEY_REGEX.match(k):
raise AirflowException(
f"The key {k!r} has to be made of alphanumeric characters, dashes, "
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_build_airflow_url_with_query(self):
"characters, dashes, dots and underscores exclusively",
AirflowException,
),
(" " * 251, "The key has to be less than 250 characters", AirflowException),
(" " * 251, f"The key: {' ' * 251} has to be less than 250 characters", AirflowException),
],
)
def test_validate_key(self, key_id, message, exception):
Expand Down
2 changes: 1 addition & 1 deletion tests/www/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_validation_fails_with_too_many_characters(self):

with pytest.raises(
validators.ValidationError,
match=r"The key has to be less than [0-9]+ characters",
match=r"The key: [x]+ has to be less than [0-9]+ characters",
):
self._validate()

Expand Down

0 comments on commit 3f8ac22

Please sign in to comment.