Skip to content

Commit

Permalink
check name lenght in local client
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimbuddy committed Dec 16, 2021
1 parent 1ffd06c commit 0cda3ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions airflow/api/client/local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def get_pools(self):
def create_pool(self, name, slots, description):
if not (name and name.strip()):
raise AirflowBadRequest("Pool name shouldn't be empty")
pool_name_length = Pool.pool.property.columns[0].type.length
if len(name) > pool_name_length:
raise AirflowBadRequest(f"pool name cannot be more than {pool_name_length} characters")
try:
slots = int(slots)
except ValueError:
Expand Down
8 changes: 5 additions & 3 deletions tests/api/client/test_local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import pytest
from freezegun import freeze_time
from sqlalchemy.exc import DataError

from airflow.api.client.local_client import Client
from airflow.example_dags import example_bash_operator
Expand Down Expand Up @@ -162,8 +161,11 @@ def test_create_pool_bad_slots(self):

def test_create_pool_name_too_long(self):
long_name = ''.join(random.choices(string.ascii_lowercase, k=300))
with pytest.raises(DataError):
Pool.create_or_update_pool(
pool_name_length = Pool.pool.property.columns[0].type.length
with pytest.raises(
AirflowBadRequest, match=f"^pool name cannot be more than {pool_name_length} characters"
):
self.client.create_pool(
name=long_name,
slots=5,
description='',
Expand Down

0 comments on commit 0cda3ab

Please sign in to comment.