Skip to content

Commit 8af1dc7

Browse files
jabberaLorin
authored and
Lorin
committed
Print the key name when max_length is exceeded (apache#43061)
* Print the key name when max_length is exceeded * Fix tests
1 parent 76fda15 commit 8af1dc7

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

airflow/utils/helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def validate_key(k: str, max_length: int = 250):
5050
if not isinstance(k, str):
5151
raise TypeError(f"The key has to be a string and is {type(k)}:{k}")
5252
if len(k) > max_length:
53-
raise AirflowException(f"The key has to be less than {max_length} characters")
53+
raise AirflowException(f"The key: {k} has to be less than {max_length} characters")
5454
if not KEY_REGEX.match(k):
5555
raise AirflowException(
5656
f"The key {k!r} has to be made of alphanumeric characters, dashes, "

tests/utils/test_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_build_airflow_url_with_query(self):
203203
"characters, dashes, dots and underscores exclusively",
204204
AirflowException,
205205
),
206-
(" " * 251, "The key has to be less than 250 characters", AirflowException),
206+
(" " * 251, f"The key: {' ' * 251} has to be less than 250 characters", AirflowException),
207207
],
208208
)
209209
def test_validate_key(self, key_id, message, exception):

tests/www/test_validators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_validation_fails_with_too_many_characters(self):
151151

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

0 commit comments

Comments
 (0)