-
Notifications
You must be signed in to change notification settings - Fork 200
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
Bug fix: unhandled exception during AjaxSelect load #727
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, I have a question since there's no issue related to this.
I decided to make a PR, not issue because I already have some workaround about it and provided snippet to reproduce. Should I have created an issue first? |
Sorry I think my comment was discarded, my question was that how is this going to fix or workaround the issue? |
Yes, my solution is to clear ajax field if there is any error on field loading. May be this is not the best solution, but due to there was no exception handling, I think there is no need to do something more serious here. |
I agree. These changes will not have any negative side effects. It would be good to see this fix in the main branch. |
I have the same problem, how soon will it be fixed? This my code:
When a user uses Cyrillic in the file names, a ValueError exception is thrown, but it cannot be handled properly:
|
@Mat0mba24 I don't think your issue is related to ajax, you are raising the error in on_model_change method. |
@aminalaee it is.I debugged the admin on error raising in insert_model, update_model and delete_model when Ajax was turned on. It was in the Ajax field load that received a field value (in @Mat0mba24 case it was a Cyrillic string), instead of the Ajax field. I have provided a snippet to reproduce the issue. |
It was a bit confusing but at least I know what the issue is now. The suggested solution works around this, but it causes a side-effect that when we are redirected to the form again, we lose the state of this select2 input because we set I think ideally we could force select2 to pass ID and Text of the selected item to backend so we could keep the input state in case of error. |
0283654
to
d0f3d01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for a temporary workaround until it is fixed properly
There is an unhandled exception in
AjaxSelect2Widget
after any exception inmodel_view.insert_model
.The error occurs when you pick something in the Ajax select box and there is an exception in the overridden
insert_model
method. Here is a part of the traceback:As you can see, the widget receives a string from the form, not the model. A common approach is to handle exceptions at the time of parsing the form.
Here is snippet to reproduce error: