Skip to content

Calculations do not to load when loading aggregate #191

@meeq

Description

@meeq

Code of Conduct

  • I agree to follow this project's Code of Conduct

AI Policy

  • I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

Versions

I was able to isolate a reproduction of this issue when upgrading:

ash_sql 0.3.11 => 0.3.12

Operating system

macOS Sonoma

Current Behavior

When ash_sql processes a query with:

  1. Aggregates (which require subquery wrapping)
  2. Calculations that depend on relationships
  3. Pagination with count: true

Something in the calculation loading pipeline fails. The calculations are added to query.calculations but aren't properly transferred through the pagination/counting transformation, resulting in #Ash.NotLoaded fields in the app

Reproduction

Sample query:

    MyApp.Client
    |> Ash.Query.for_read(:read)
    |> Ash.Query.load([
      # aggregate
      :most_recent_payment_date,
      # calculation depending on relationship
      :active_subscription_processor,
      active_subscription: [:payment_processor]
    ])
    |> Ash.Query.page(limit: 50, offset: 0, count: true)

When reading this query, the most_recent_payment_date and active_subscription_processor will not be loaded even though they should be.

This is a standalone .exs script that reproduces the issues I found with loading calculations with aggregates.
It requires a local test postgres database to exercise ash_sql.

ash_bug_reproduction.exs.zip

Expected Behavior

I expect the calculations, relationships, and aggregates to load.

For now, I am working around this issue by pinning ash_sql to 0.3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions