Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError (Delete) #72

Closed
Ysnz opened this issue Jan 25, 2024 · 6 comments · Fixed by #74
Closed

ValueError (Delete) #72

Ysnz opened this issue Jan 25, 2024 · 6 comments · Fixed by #74
Assignees

Comments

@Ysnz
Copy link

Ysnz commented Jan 25, 2024

Description

When attempting to delete an object in the admin interface, an internal server error occurs. The error is specifically related to the attempt to convert a UUID ('90b608d0-1684-4b5e-adf3-fb5c0c21ca96') to an integer during the deletion process.

How To Reproduce

Steps to reproduce the behavior:

  1. Go to the admin interface.
  2. Navigate to the page where you can delete an object.
  3. Attempt to delete an object with the UUID '90b608d0-1684-4b5e-adf3-fb5c0c21ca96'.
  4. Observe the internal server error.

Expected behavior

The deletion process should occur without errors, and the object with the provided UUID should be deleted successfully.

Additional context

The issue is related to the attempt to convert UUIDs to integers during the deletion process, resulting in a ValueError.

Screenshots

image

@KengoWada
Copy link
Collaborator

Hey @Ysnz thanks for reporting the bug. I'm going to try and replicate it to confirm the bug.

@KengoWada
Copy link
Collaborator

Hey @EricOuma I can confirm the bug that has been reported. I will start working on a fix. Please assign this to me and mark it as a bug.

@EricOuma
Copy link
Contributor

EricOuma commented Feb 9, 2024

@KengoWada Let me know how you plan to approach the problem before you make a PR.

@KengoWada
Copy link
Collaborator

KengoWada commented Feb 9, 2024

@EricOuma this is my current solution in collections.py
TypesenseCollection.delete

- delete_params = {"filter_by": f"id:{[int(obj['id']) for obj in self.data]}"}

+ object_ids = []
+ for obj in self.data:
+     try:
+         object_id = int(obj["id"])
+     except ValueError:
+         object_id = str(obj["id"])
+     object_ids.append(object_id)
+
+ if all(isinstance(id_, int) for id_ in object_ids):
+     filter_by = f"id:{object_ids}"
+ else:
+     filter_by = f"id: {object_ids}".replace("'", "")
+
+ delete_params = {"filter_by": filter_by}

WDYT

@EricOuma
Copy link
Contributor

EricOuma commented Feb 9, 2024 via email

@KengoWada
Copy link
Collaborator

@EricOuma Yeah, that's the way to go. You need to remove the single quotes that Python adds to strings. According to Typesense filter_by formatting rules.

- delete_params = {"filter_by": f"id:{[int(obj['id']) for obj in self.data]}"}
+ delete_params = {"filter_by": f"id: {[obj['id'] for obj in self.data]}".replace("'", "")}

KengoWada added a commit to KengoWada/django-typesense that referenced this issue Feb 10, 2024
@KengoWada KengoWada mentioned this issue Feb 10, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants