
Sqlalchemy: Case-Sensitivity
I came across an issue with a Registration Form where it was allowing duplicate accounts to be made due to a lack of character case-sensitivity comparison. There were 2 solutions that kept appearing in online forums. Option 1: was to use "from sqlalchemy import func" and incorporate func.lower() or func.upper() in my query to convert the database and user input to the specified case before comparing them against one another. Option 2: was to use ILIKE in the query, thus making it a case-insensitive comparison by nature. Option 2 seemed to be the easiest to use. However, upon testing I believe it was not working in the way I needed. The comparison seemed to be counting the database characters as equivalent to any combination of user input characters as long as the same letters were present. So the word "flask" was equal to "ksalf" and would then raise a validation error that the word already existed even though it really did not. I later found out that it was because I had added the wildcard character '%' to the front and back of my variable for the user input. This made a huge difference in the pattern matching for the ILIKE operator. So the fix was just to remove the wildcard characters from around my variable. Lesson learned! Anyway, either option was a decent solution.