A bug has been reported where CSV tag imports fail when tag names differ in case (e.g., ‘ABC’ vs ‘abc’), despite tags being case-insensitive in uniqueness. The issue stems from Tag.find_by_name being case-insensitive (correct) but Tag.find_by(name: ) being case-sensitive (incorrect), especially when used with tag groups. RGJ initially reproduced the issue with a tag group, and gabriel confirmed the error occurs with tag groups even if regular tags work. RGJ clarified that SiteSetting.force_lowercase_tags was disabled, which affects behavior. gabriel noted the setting’s relevance and shared a test case. RGJ later corrected their initial report, confirming the issue lies in inconsistent case handling between find_by_name and find_by(name:), particularly in tag group contexts. A fix is needed to ensure case-insensitive matching during CSV import. A PR is welcome sam suggested modifying find_by_name to use case-insensitive lookup, and gabriel has already submitted a PR to address the tag group case.
which is a bad pattern, since find_by_name is case sensitive and create! is not [1] so it errors out with ActiveRecord::RecordInvalid : Validation failed: Name has already been taken
This should be something like
tag = Tag.where('name ILIKE ?', tag_name).first || Tag.create!(name: tag_name)
because validates :name, presence: true, uniqueness: { case_sensitive: false }↩︎
Tag.find_by_name is case insensitive (good) and Tag.find_by(name: ) is case sensitive (bad).
This is because David already fixed it for tags 7 years ago by overriding the find_by_name method.