Add subquery-based alias filter methods to ImageConditions for repository layer support.
File to Modify
src/ai/backend/manager/repositories/image/options.py
Changes Required
Add 4 methods to ImageConditions class (after line ~159, after architecture filters):
1. by_alias_contains
@staticmethod
def by_alias_contains(spec: StringMatchSpec) -> QueryCondition:
def inner() -> sa.sql.expression.ColumnElement[bool]:
subquery = sa.select(ImageAliasRow.image_id).where(
ImageAliasRow.alias.ilike(f"%{spec.value}%")
if spec.case_insensitive
else ImageAliasRow.alias.like(f"%{spec.value}%")
)
condition = ImageRow.id.in_(subquery)
if spec.negated:
condition = sa.not_(condition)
return condition
return inner
2. by_alias_equals
@staticmethod
def by_alias_equals(spec: StringMatchSpec) -> QueryCondition:
def inner() -> sa.sql.expression.ColumnElement[bool]:
subquery = sa.select(ImageAliasRow.image_id).where(
sa.func.lower(ImageAliasRow.alias) == spec.value.lower()
if spec.case_insensitive
else ImageAliasRow.alias == spec.value
)
condition = ImageRow.id.in_(subquery)
if spec.negated:
condition = sa.not_(condition)
return condition
return inner
3. by_alias_starts_with
@staticmethod
def by_alias_starts_with(spec: StringMatchSpec) -> QueryCondition:
def inner() -> sa.sql.expression.ColumnElement[bool]:
subquery = sa.select(ImageAliasRow.image_id).where(
ImageAliasRow.alias.ilike(f"{spec.value}%")
if spec.case_insensitive
else ImageAliasRow.alias.like(f"{spec.value}%")
)
condition = ImageRow.id.in_(subquery)
if spec.negated:
condition = sa.not_(condition)
return condition
return inner
4. by_alias_ends_with
@staticmethod
def by_alias_ends_with(spec: StringMatchSpec) -> QueryCondition:
def inner() -> sa.sql.expression.ColumnElement[bool]:
subquery = sa.select(ImageAliasRow.image_id).where(
ImageAliasRow.alias.ilike(f"%{spec.value}")
if spec.case_insensitive
else ImageAliasRow.alias.like(f"%{spec.value}")
)
condition = ImageRow.id.in_(subquery)
if spec.negated:
condition = sa.not_(condition)
return condition
return inner
Import Check
Verify ImageAliasRow is imported at the top of the file (should already be there on line ~13).
Implementation Notes
-
All methods use IN subquery pattern: ImageRow.id.in_(subquery)
-
Subquery selects ImageAliasRow.image_id where alias matches the filter
-
Supports case_insensitive flag (ilike vs like)
-
Supports negated flag (wrapped with sa.not_())
-
Follows same pattern as existing by_name_\* and by_architecture_\* methods
Acceptance Criteria
JIRA Issue: BA-4819
Add subquery-based alias filter methods to ImageConditions for repository layer support.
File to Modify
src/ai/backend/manager/repositories/image/options.pyChanges Required
Add 4 methods to
ImageConditionsclass (after line ~159, after architecture filters):1. by_alias_contains
2. by_alias_equals
3. by_alias_starts_with
4. by_alias_ends_with
Import Check
Verify
ImageAliasRowis imported at the top of the file (should already be there on line ~13).Implementation Notes
All methods use IN subquery pattern:
ImageRow.id.in_(subquery)Subquery selects
ImageAliasRow.image_idwhere alias matches the filterSupports
case_insensitiveflag (ilike vs like)Supports
negatedflag (wrapped with sa.not_())Follows same pattern as existing
by_name_\*andby_architecture_\*methodsAcceptance Criteria
4 filter methods added (contains, equals, starts_with, ends_with)
All methods use IN subquery pattern
case_insensitive and negated flags supported
Follows existing code style (same pattern as name/architecture filters)
ImageAliasRow import verified
JIRA Issue: BA-4819