Verified Commit 14347232 authored by Kevin Morris's avatar Kevin Morris
Browse files

fix: treat all keywords as lowercase when updating

In addition, treat package search by keywords as lowercase.

Closes #296, #297, #298, #301

Signed-off-by: Kevin Morris's avatarKevin Morris <>
parent 8387f325
Pipeline #16004 passed with stages
in 3 minutes and 29 seconds
......@@ -124,6 +124,7 @@ class PackageSearch:
def _search_by_keywords(self, keywords: Set[str]) -> orm.Query:
keywords = set(k.lower() for k in keywords)
self.query = self.query.filter(PackageKeyword.Keyword.in_(keywords))
return self
......@@ -95,24 +95,28 @@ async def pkgbase_flag_comment(request: Request, name: str):
async def pkgbase_keywords(request: Request, name: str,
keywords: str = Form(default=str())):
pkgbase = get_pkg_or_base(name, PackageBase)
keywords = set(keywords.split(" "))
# Lowercase all keywords. Our database table is case insensitive,
# and providing CI duplicates of keywords is erroneous.
keywords = set(k.lower() for k in keywords.split(" "))
# Delete all keywords which are not supplied by the user.
other_keywords = pkgbase.keywords.filter(
other_keyword_strings = [kwd.Keyword for kwd in other_keywords]
existing_keywords = set(
kwd.Keyword for kwd in
with db.begin():
other_keywords = pkgbase.keywords.filter(
other_keyword_strings = set(
kwd.Keyword.lower() for kwd in other_keywords)
existing_keywords = set(
kwd.Keyword.lower() for kwd in
for keyword in keywords.difference(existing_keywords):
new_keywords = keywords.difference(existing_keywords)
for keyword in new_keywords:
db.create(PackageKeyword, PackageBase=pkgbase, Keyword=keyword)
return RedirectResponse(f"/pkgbase/{name}",
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment