ash-project / ash_admin

A super-admin UI dashboard for Ash Framework applications, built with Phoenix LiveView.
https://hexdocs.pm/ash_admin
MIT License
106 stars 48 forks source link

Relationship's private field in table columns causes query to produce no result #109

Closed shirishgoyal closed 7 months ago

shirishgoyal commented 7 months ago

Describe the bug

Under domain Accounts

  1. A User resource 1.1. with fields :id and :email 1.2 with relationship belongs_to :role
  2. A Role resource 2.1 with fields :id and :name 2.2 with relationship has_many :users

To Reproduce

Query:

Accounts.User |> Ash.Query.select([])|> Ash.Query.load([:email, :role])|>Ash.read(page: [count: true, limit: 20], domain: Accounts)

Query similiar to above is being used in Admin to fetch results but it doesn't show any error or warning

Expected behavior

It should show role field with nil value OR show warning in console that private field is being exposed in query

Instead we get below error

{:error,
 %Ash.Error.Unknown{
   errors: [
     %Ash.Error.Unknown.UnknownError{
       error: "filter: Could not cast expression: Ash.Query.Operator.In id [#Ash.NotLoaded<:attribute, field: :role_id>]",
       field: nil,
       splode: Ash.Error,
       bread_crumbs: [],
       vars: [],
       path: [:role, :filter],
       stacktrace: #Splode.Stacktrace<>,
       class: :unknown
     }
   ],
   changeset: nil,
   query: #Ash.Query<
     resource: Accounts.User,
     load: [role: #Ash.Query<resource: Accounts.Role>],
     errors: [
       %Ash.Error.Unknown.UnknownError{
         error: "filter: Could not cast expression: Ash.Query.Operator.In id [#Ash.NotLoaded<:attribute, field: :role_id>]",
         field: nil,
         splode: Ash.Error,
         bread_crumbs: [],
         vars: [],
         path: [:role, :filter],
         stacktrace: #Splode.Stacktrace<>,
         class: :unknown
       }
     ],
     select: [:email, :id]
   >,
   action_input: nil,
   splode: Ash.Error,
   bread_crumbs: [],
   vars: [],
   path: [:role],
   stacktrace: #Splode.Stacktrace<>,
   class: :unknown
 }}

Runtime

zachdaniel commented 7 months ago

Hey there! Can you try Ash 3.0.0-rc.19? We've fixed something that looks similar to this issue :)

shirishgoyal commented 7 months ago

With new changes, it is not erroring but now the related field is visible even when it hasn't been made public. Is that the new intended behaviour?

zachdaniel commented 7 months ago

Yep!