serializers.ValidationError always returning str in 'detail' #9252
Unanswered
FelipeFranke5
asked this question in
Question & Answer
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My apologies in advance for both the bad English and very noob question folks.
Hi there! I'm having trouble converting certain values from str to int, when raising serializers.ValidationError.
To be more specific, when raising serializers.ValidationError, I only add the "detail" param, passing a list of dictionaries (The key == str, and value == str | int), here is an example:
Note0: This is NOT the
validate_.field.
yet (Although, this function is running inside avalidate
andvalidate_.field._
method), I'm using a helper function, which is a "OpenAIActorAgeValidator" and "OpenAIActorNameValidator" class method.Note1: I'm using OpenAI to perform some validations, in order to practice both usage of their API and serializer validations.
Basically, first I retrieve and convert the actor_age as a str and the chatbot response as a int, using separate variables. If ValidationError is raised, I point the "correct_age_or_response" to the int converted correct age variable (I called it or_response because OpenAI may return a different output than simply the age, I'll deal with that issue later..)
But after doing some tests, it seems like ValidationError is converting the variable back to str:
Is that the default behaviour for dictionaries in this case? I tried changing the variable to make sure it is in fact a int, and this only happens when raising ValidationError.
Thanks !!
Beta Was this translation helpful? Give feedback.
All reactions