Skip to content

Commit

Permalink
fix error after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
frascuchon committed Jan 28, 2025
1 parent 68e0fea commit bd6b7ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 1 addition & 6 deletions argilla-server/src/argilla_server/contexts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ async def create_user(
if await get_user_by_username(db, user_attrs["username"]) is not None:
raise NotUniqueError(f"User username `{user_attrs['username']}` is not unique")

if user_id := user_attrs.get("id"):
if await User.get(db, id=user_id) is not None:
raise NotUniqueError(f"User with id `{user_id}` is not unique")

user = await User.create(
db,
new_user = User(
id=user_attrs.get("id"),
first_name=user_attrs["first_name"],
last_name=user_attrs["last_name"],
Expand Down
9 changes: 9 additions & 0 deletions argilla-server/src/argilla_server/validators/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class UserCreateValidator:
@classmethod
async def validate(cls, db: AsyncSession, user: User) -> None:
await cls._validate_username(db, user)
await cls._validate_user_id(db, user)

@classmethod
async def _validate_username(cls, db, user: User):
Expand All @@ -39,3 +40,11 @@ async def _validate_unique_username(cls, db, user):
async def _validate_username_length(cls, user: User):
if len(user.username) < 1:
raise UnprocessableEntityError("Username must be at least 1 characters long")

@classmethod
async def _validate_user_id(cls, db, user: User):
if user.id is None:
return

if await User.get(db, id=user.id) is not None:
raise NotUniqueError(f"User with id `{user.id}` is not unique")

0 comments on commit bd6b7ee

Please sign in to comment.