-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
Fixed Nonetype error! #3233
Fixed Nonetype error! #3233
Conversation
This is absolutely right. However I think the solution of the flash message + redirect is perhaps not what we want. Take for example this non-existing artist: https://listenbrainz.org/artist/37e9d7b2-7779-41b2-b2eb-3685351caad2/ Sure, it's pretty ugly and the error page could definitely be improved, but I mainly wanted to show that this is the usual mechanism we go for. See the implementation of the above example here: listenbrainz-server/listenbrainz/webserver/views/entity_pages.py Lines 159 to 161 in 7935cc8
|
To fix this, I modified the Here’s the updated code for clarity: result_row = result.fetchone()
if result_row is None:
return jsonify({"error": f"Artist not found in the database"}), 404
else:
artist_mbid = result_row[0]
data = {
"algorithm": "session_based_days_7500_session_300_contribution_5_threshold_10_limit_100_filter_True_skip_30",
"artist_mbid": artist_mbid
}
return jsonify(data) I initially considered using a flash message and redirect, but after reviewing the project’s conventions (e.g., in |
Hey, regarding your previous comment, I want to raise an important topic: the comment seems to me to have been written by a large language model, and AI-detection tools seem to support that theory. We do not accept any use of AI or LLMs for communication, for problem solving or for generating code.
|
Thanks for the review @MonkeyDo |
I would like some clarification: did you use AI to generate text for the PR, comments or code, or only to format your own text content? |
Sure, i just written my comment and converted it to .md format for my own text content thats it! |
Well, it definitely feels like that is a lie. For clarity, I am here to evaluate you on the quality of your code and your problem-solving skills, NOT on how well you speak english. Please understand that when you use an LLM for something, even if it is just to rephrase your comments, it is practically impossible for me to evaluate if you used an LLM for all the rest or not, making me doubt if you solved the problems by yourself. I am not interested in mentoring an LLM, and it puts you in a bad light. |
Sure i understand and again i wants to applogize for use of LLM for formatting my own content. I accept my mistake and i understand that posting original is far better and trustable than posting polished !! |
Problem
I encountered an issue in the
artist_similarity
function withinlistenbrainz/webserver/views/explore.py
at line 36. The specific error was aTypeError: 'NoneType' object is not subscriptable
, which occurred when I tried to access the first element ([0]
) of a database query result usingartist_mbid = result.fetchone()[0]
. The root cause was that thefetchone()
method returnedNone
when the database query didn’t find any matching records, likely because the artist name or ID I was searching for didn’t exist in the database, or there might be a logic issue in the SQL query itself. This caused the application to crash since I was attempting to index aNone
value, which isn’t possible.This issue could affect users trying to explore artist similarity if the queried artist isn’t found, leading to an unhandled error instead of a graceful response.
Solution
To fix this, I modified the
artist_similarity
function to handle the case wherefetchone()
returnsNone
. I introduced a new variable,result_row
, to store the result ofresult.fetchone()
. Then, I added a conditional check: ifresult_row
isNone
, I flash a message to the user saying "Artist not found" and redirect them to the explore index page. Ifresult_row
is notNone
, I proceed to extract theartist_mbid
fromresult_row[0]
and continue with the rest of the function as before. This ensures the application doesn’t crash when the artist isn’t found and provides a better user experience by redirecting with a helpful message.Here’s the updated code for clarity:
I considered other approaches, like adding a default value for
artist_mbid
, but I felt that redirecting with a flash message was more appropriate for the user experience in this context. I also didn’t modify the underlying SQL query since the issue seems to be more about handling the absence of results rather than a query error, but this could be revisited if needed.Action
I’d appreciate it if the reviewers could take a look at the conditional logic I added to ensure it aligns with the project’s standards for error handling and user feedback. Additionally, if there are any suggestions for improving the flash message or the redirect behavior, I’d be happy to incorporate them. No other actions are needed beyond merging the change.