From 3f8ac22cafa6bfe3c61da781f8bc7de9bca9bd47 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 17 Oct 2024 03:48:16 -0400 Subject: [PATCH] Print the key name when max_length is exceeded (#43061) * Print the key name when max_length is exceeded * Fix tests --- airflow/utils/helpers.py | 2 +- tests/utils/test_helpers.py | 2 +- tests/www/test_validators.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/airflow/utils/helpers.py b/airflow/utils/helpers.py index 8c08acc66be24..8b83e3b134960 100644 --- a/airflow/utils/helpers.py +++ b/airflow/utils/helpers.py @@ -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, " diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index 041dba2a90e4f..ed1b1134d842a 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -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): diff --git a/tests/www/test_validators.py b/tests/www/test_validators.py index e92cc9d80453d..02923f9e2afd8 100644 --- a/tests/www/test_validators.py +++ b/tests/www/test_validators.py @@ -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()