Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/aleph/db/accessors/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_total_detailed_balance(
query = (
select(func.sum(AlephBalanceDb.balance))
.where(
(AlephBalanceDb.address == address)
AlephBalanceDb.address.ilike(address)
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ilike for address comparison is problematic because it's a SQL pattern matching operator that treats % and _ as wildcards. If an address contains these characters, they will be interpreted as wildcards rather than literal characters, potentially matching multiple addresses incorrectly.

For case-insensitive exact matching, consider using func.lower() on both sides of the comparison instead:

func.lower(AlephBalanceDb.address) == func.lower(address)

This approach:

  • Performs exact case-insensitive matching without wildcard interpretation
  • Is clearer in intent
  • Maintains SQL injection safety
  • Can potentially use functional indexes if needed for performance

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent address comparison methods across the codebase. While get_total_detailed_balance now uses case-insensitive matching, other functions in the same file (get_balance_by_chain at line 22 and get_total_balance at line 69) still use exact match (==).

This inconsistency could lead to:

  • Different results for the same address with different casing across different API endpoints
  • Confusion for developers maintaining this code
  • Unexpected behavior for API consumers

Consider applying the same case-insensitive logic consistently across all address comparison functions in this file.

Copilot uses AI. Check for mistakes.
& (AlephBalanceDb.chain == chain)
& ((AlephBalanceDb.dapp.is_(None)) if not include_dapps else True)
)
Expand All @@ -104,7 +104,7 @@ def get_total_detailed_balance(
query = (
select(AlephBalanceDb.chain, func.sum(AlephBalanceDb.balance).label("balance"))
.where(
(AlephBalanceDb.address == address)
AlephBalanceDb.address.ilike(address)
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ilike for address comparison is problematic because it's a SQL pattern matching operator that treats % and _ as wildcards. If an address contains these characters, they will be interpreted as wildcards rather than literal characters, potentially matching multiple addresses incorrectly.

For case-insensitive exact matching, consider using func.lower() on both sides of the comparison instead:

func.lower(AlephBalanceDb.address) == func.lower(address)

This approach:

  • Performs exact case-insensitive matching without wildcard interpretation
  • Is clearer in intent
  • Maintains SQL injection safety
  • Can potentially use functional indexes if needed for performance

Copilot uses AI. Check for mistakes.
& ((AlephBalanceDb.dapp.is_(None)) if not include_dapps else True)
)
.group_by(AlephBalanceDb.chain)
Expand All @@ -118,7 +118,7 @@ def get_total_detailed_balance(
query = (
select(func.sum(AlephBalanceDb.balance))
.where(
(AlephBalanceDb.address == address)
AlephBalanceDb.address.ilike(address)
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ilike for address comparison is problematic because it's a SQL pattern matching operator that treats % and _ as wildcards. If an address contains these characters, they will be interpreted as wildcards rather than literal characters, potentially matching multiple addresses incorrectly.

For case-insensitive exact matching, consider using func.lower() on both sides of the comparison instead:

func.lower(AlephBalanceDb.address) == func.lower(address)

This approach:

  • Performs exact case-insensitive matching without wildcard interpretation
  • Is clearer in intent
  • Maintains SQL injection safety
  • Can potentially use functional indexes if needed for performance

Copilot uses AI. Check for mistakes.
& ((AlephBalanceDb.dapp.is_(None)) if not include_dapps else True)
)
.group_by(AlephBalanceDb.address)
Expand Down
Loading