Skip to content

Commit

Permalink
[BUGFIX] Renamed 'response' to 'existing_response' to avoid variable …
Browse files Browse the repository at this point in the history
…re-declaring (#5383)

# Description
When checking collisions of responses to avoid duplicate responses given
by the same user to the same question, the response argument is
redeclared and the `response.user_id == response.user_id ` will always
be satisfied, raising an exception.

Closes #5357

**Type of change**

- Bug fix (non-breaking change which fixes an issue)


**How Has This Been Tested**

Changes done locally, installed the local version and tested on top of
our Argilla server with this piece of code (details were obfuscated):
```

for user in client.users:
       record_to_add.responses.add(rg.Response("label_name", label, user_id=user.id, status="submitted"))
```
  • Loading branch information
maxserras authored Aug 7, 2024
1 parent b7ac946 commit 1d75656
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions argilla-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ These are the section headers that we use:

- Added new endpoint `GET /api/v1/datsets/:dataset_id/users/progress` to compute the users progress. ([#5367](https://github.com/argilla-io/argilla/pull/5367))

### Fixed

- Fixed response duplicate checking ([#5357](https://github.com/argilla-io/argilla/issues/5357))

## [2.0.0](https://github.com/argilla-io/argilla/compare/v2.0.0rc1...v2.0.0)

> [!IMPORTANT]
Expand Down
4 changes: 2 additions & 2 deletions argilla/src/argilla/records/_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ def add(self, response: Response) -> None:

def _check_response_already_exists(self, response: Response) -> None:
"""Checks if a response for the same question name and user id already exists"""
for response in self.__responses_by_question_name[response.question_name]:
if response.user_id == response.user_id:
for existing_response in self.__responses_by_question_name[response.question_name]:
if existing_response.user_id == response.user_id:
raise ArgillaError(
f"Response for question with name {response.question_name!r} and user id {response.user_id!r} "
f"already found. The responses for the same question name do not support more than one user"
Expand Down

0 comments on commit 1d75656

Please sign in to comment.