Skip to content

Commit 485f3ff

Browse files
authored
[Refactor] remove name validations for dataset workspaces and usernames (#5575)
# Description <!-- Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change. --> This PR removes name pattern validations for datasets, workspaces, and users. **Type of change** <!-- Please delete options that are not relevant. Remember to title the PR according to the type of change --> - Refactor (change restructuring the codebase without changing functionality) - Improvement (change adding some improvement to an existing functionality) **How Has This Been Tested** <!-- Please add some reference about how your feature has been tested. --> **Checklist** <!-- Please go over the list and make sure you've taken everything into account --> - I added relevant documentation - I followed the style guidelines of this project - I did a self-review of my code - I made corresponding changes to the documentation - I confirm My changes generate no new warnings - I have added tests that prove my fix is effective or that my feature works - I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/)
1 parent 83996fe commit 485f3ff

File tree

12 files changed

+15
-126
lines changed

12 files changed

+15
-126
lines changed

argilla-server/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ These are the section headers that we use:
1616

1717
## [Unreleased]()
1818

19+
### Removed
20+
21+
- Removed name pattern validation for Workspaces, Datasets, and Users. ([#5575](https://github.com/argilla-io/argilla/pull/5575))
22+
1923
## [2.3.0](https://github.com/argilla-io/argilla/compare/v2.2.0...v2.3.0)
2024

2125
### Added

argilla-server/src/argilla_server/api/schemas/v1/datasets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
except ImportError:
2626
from typing_extensions import Annotated
2727

28-
DATASET_NAME_REGEX = r"^(?!-|_)[a-zA-Z0-9-_ ]+$"
2928
DATASET_NAME_MIN_LENGTH = 1
3029
DATASET_NAME_MAX_LENGTH = 200
3130
DATASET_GUIDELINES_MIN_LENGTH = 1
3231
DATASET_GUIDELINES_MAX_LENGTH = 10000
3332

3433
DatasetName = Annotated[
35-
constr(regex=DATASET_NAME_REGEX, min_length=DATASET_NAME_MIN_LENGTH, max_length=DATASET_NAME_MAX_LENGTH),
34+
constr(
35+
min_length=DATASET_NAME_MIN_LENGTH,
36+
max_length=DATASET_NAME_MAX_LENGTH,
37+
),
3638
Field(..., description="Dataset name"),
3739
]
3840

argilla-server/src/argilla_server/api/schemas/v1/users.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from argilla_server.enums import UserRole
2020
from argilla_server.pydantic_v1 import BaseModel, Field, constr
2121

22-
USER_USERNAME_REGEX = "^(?!-|_)[A-za-z0-9-_]+$"
2322
USER_PASSWORD_MIN_LENGTH = 8
2423
USER_PASSWORD_MAX_LENGTH = 100
2524

@@ -43,7 +42,7 @@ class Config:
4342
class UserCreate(BaseModel):
4443
first_name: constr(min_length=1, strip_whitespace=True)
4544
last_name: Optional[constr(min_length=1, strip_whitespace=True)]
46-
username: str = Field(regex=USER_USERNAME_REGEX, min_length=1)
45+
username: str = Field(..., min_length=1)
4746
role: Optional[UserRole]
4847
password: str = Field(min_length=USER_PASSWORD_MIN_LENGTH, max_length=USER_PASSWORD_MAX_LENGTH)
4948

argilla-server/src/argilla_server/api/schemas/v1/workspaces.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
from typing import List
1717
from uuid import UUID
1818

19-
from argilla_server.constants import ES_INDEX_REGEX_PATTERN
2019
from argilla_server.pydantic_v1 import BaseModel, Field
2120

22-
WORKSPACE_NAME_REGEX = ES_INDEX_REGEX_PATTERN
23-
2421

2522
class Workspace(BaseModel):
2623
id: UUID
@@ -33,7 +30,7 @@ class Config:
3330

3431

3532
class WorkspaceCreate(BaseModel):
36-
name: str = Field(regex=WORKSPACE_NAME_REGEX, min_length=1)
33+
name: str = Field(min_length=1)
3734

3835

3936
class Workspaces(BaseModel):

argilla-server/src/argilla_server/cli/database/users/migrate.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import typer
1919
import yaml
2020

21-
from argilla_server.api.schemas.v1.users import USER_USERNAME_REGEX
22-
from argilla_server.api.schemas.v1.workspaces import WORKSPACE_NAME_REGEX
2321
from argilla_server.database import AsyncSessionLocal
2422
from argilla_server.models import User, UserRole
2523
from argilla_server.pydantic_v1 import BaseModel, Field, constr
@@ -31,12 +29,12 @@
3129

3230

3331
class WorkspaceCreate(BaseModel):
34-
name: str = Field(..., regex=WORKSPACE_NAME_REGEX, min_length=1)
32+
name: str = Field(..., min_length=1)
3533

3634

3735
class UserCreate(BaseModel):
3836
first_name: constr(strip_whitespace=True)
39-
username: str = Field(..., regex=USER_USERNAME_REGEX, min_length=1)
37+
username: str = Field(..., min_length=1)
4038
role: UserRole
4139
api_key: constr(min_length=1)
4240
password_hash: constr(min_length=1)

argilla-server/src/argilla_server/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,4 @@
3939
# The metadata field name prefix defined for protected (non-searchable) values
4040
PROTECTED_METADATA_FIELD_PREFIX = "_"
4141

42-
ES_INDEX_REGEX_PATTERN = r"^(?!-|_)[a-z0-9-_]+$"
43-
4442
JS_MAX_SAFE_INTEGER = 9007199254740991

argilla-server/tests/unit/api/handlers/v1/test_datasets.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,6 @@ async def test_create_dataset_with_invalid_length_guidelines(
916916
"dataset_json",
917917
[
918918
{"name": ""},
919-
{"name": "123$abc"},
920-
{"name": "unit@test"},
921-
{"name": "-test-dataset"},
922-
{"name": "_test-dataset"},
923919
{"name": "a" * (DATASET_NAME_MAX_LENGTH + 1)},
924920
{"name": "test-dataset", "guidelines": ""},
925921
{"name": "test-dataset", "guidelines": "a" * (DATASET_GUIDELINES_MAX_LENGTH + 1)},
@@ -4777,10 +4773,6 @@ async def test_update_dataset(self, async_client: "AsyncClient", db: "AsyncSessi
47774773
[
47784774
{"name": None},
47794775
{"name": ""},
4780-
{"name": "123$abc"},
4781-
{"name": "unit@test"},
4782-
{"name": "-test-dataset"},
4783-
{"name": "_test-dataset"},
47844776
{"name": "a" * (DATASET_NAME_MAX_LENGTH + 1)},
47854777
{"name": "test-dataset", "guidelines": ""},
47864778
{"name": "test-dataset", "guidelines": "a" * (DATASET_GUIDELINES_MAX_LENGTH + 1)},

argilla-server/tests/unit/api/handlers/v1/users/test_create_user.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,6 @@ async def test_create_user_with_existent_username(
201201

202202
assert (await db.execute(select(func.count(User.id)))).scalar() == 2
203203

204-
async def test_create_user_with_invalid_username(
205-
self, db: AsyncSession, async_client: AsyncClient, owner_auth_header: dict
206-
):
207-
response = await async_client.post(
208-
self.url(),
209-
headers=owner_auth_header,
210-
json={
211-
"first_name": "First name",
212-
"last_name": "Last name",
213-
"username": "invalid username",
214-
"password": "12345678",
215-
},
216-
)
217-
218-
assert response.status_code == 422
219-
assert (await db.execute(select(func.count(User.id)))).scalar() == 1
220-
221204
async def test_create_user_with_invalid_min_length_first_name(
222205
self, db: AsyncSession, async_client: AsyncClient, owner_auth_header: dict
223206
):

argilla-server/tests/unit/api/handlers/v1/workspaces/test_create_workspace.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ async def test_create_workspace_with_existent_name(
8787

8888
assert (await db.execute(select(func.count(Workspace.id)))).scalar() == 1
8989

90-
async def test_create_workspace_with_invalid_name(
91-
self, db: AsyncSession, async_client: AsyncClient, owner_auth_header: dict
92-
):
93-
response = await async_client.post(
94-
self.url(),
95-
headers=owner_auth_header,
96-
json={"name": "invalid name"},
97-
)
98-
99-
assert response.status_code == 422
100-
assert (await db.execute(select(func.count(Workspace.id)))).scalar() == 0
101-
10290
async def test_create_workspace_with_invalid_min_length_name(
10391
self, db: AsyncSession, async_client: AsyncClient, owner_auth_header: dict
10492
):

argilla-server/tests/unit/cli/database/users/test_create.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
from typing import TYPE_CHECKING
1616

1717
import pytest
18-
from argilla_server.contexts import accounts
19-
from argilla_server.models import User, UserRole, Workspace
2018
from click.testing import CliRunner
2119
from typer import Typer
2220

21+
from argilla_server.contexts import accounts
22+
from argilla_server.models import User, UserRole, Workspace
2323
from tests.factories import UserSyncFactory, WorkspaceSyncFactory
2424

2525
if TYPE_CHECKING:
@@ -131,17 +131,6 @@ def test_create_with_input_username(sync_db: "Session", cli_runner: CliRunner, c
131131
assert sync_db.query(User).filter_by(username="username").first()
132132

133133

134-
def test_create_with_invalid_username(sync_db: "Session", cli_runner: CliRunner, cli: Typer):
135-
result = cli_runner.invoke(
136-
cli,
137-
"database users create --first-name first-name --username -Invalid-Username --password 12345678 --role owner",
138-
)
139-
140-
assert result.exit_code == 1
141-
assert sync_db.query(User).count() == 0
142-
assert sync_db.query(Workspace).count() == 0
143-
144-
145134
def test_create_with_existing_username(sync_db: "Session", cli_runner: CliRunner, cli: Typer):
146135
UserSyncFactory.create(username="username")
147136

@@ -243,15 +232,3 @@ def test_create_with_existent_workspaces(sync_db: "Session", cli_runner: CliRunn
243232
user = sync_db.query(User).filter_by(username="username").first()
244233
assert user
245234
assert [ws.name for ws in user.workspaces] == ["workspace-a", "workspace-b", "workspace-c"]
246-
247-
248-
def test_create_with_invalid_workspaces(sync_db: "Session", cli_runner: CliRunner, cli: Typer):
249-
result = cli_runner.invoke(
250-
cli,
251-
"database users create --first-name first-name --username username --role owner --password 12345678 "
252-
"--workspace workspace-a --workspace 'invalid workspace' --workspace workspace-c",
253-
)
254-
255-
assert result.exit_code == 1
256-
assert sync_db.query(User).count() == 0
257-
assert sync_db.query(Workspace).count() == 0

0 commit comments

Comments
 (0)