Skip to content

Calculations do not to load when loading aggregate #191

Closed

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

Activity

  1. added
    bugSomething isn't working
    on Nov 14, 2025
  2. added theissue type on Nov 14, 2025
  3. changed the title [-]Calculations fail to load when loading aggregate[/-] [+]Calculations do not to load when loading aggregate[/+] on Nov 14, 2025
  4. zachdaniel commented on Nov 15, 2025

    @zachdaniel
    Contributor
  5. zachdaniel commented on Nov 16, 2025

    @zachdaniel
    Contributor

    Fixed in main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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