MartinVolerich
Having received great answers to my questions about json_api endpoints, I have just come across a situation where I am requesting “included” resources using the Swagger / OpenAPI UI, which will respond with the public attributes or any “default_fields” set in the related resource’s json_api block.
But… when I also add a “default_fields” line to the parent resource (in the domain’s json_api base_routes, I find that I’m correctly receiving those default_fields, but… it has the unexpected/unwanted side effect of no longer returning the public fields (or default_fields) of the related included resource.
Is this a bug? Or is there something else I can or should configure to get this to work?
Thanks
Martin
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
This sounds like a bug. Please work up a reproduction or failing test and submit an issue
MartinVolerich
Will do. What are the guidelines and best practices for doing that on this project (and I assume that this is scoped to AshJsonApi)?
Also I was stepping through the code yesterday (using pry) to see what is taking place and am happy to continue digging into this further to get a sense of what needs to be changed. Would that be helpful?
Martin
zachdaniel
Ideally a test in a relevant test file, there is a test somewhere for inclusion of related resources IIRC. Barring that, a separate repo with a minimal reproduction.
As for this issue, it sounds like there is some kind of mishandling of
fieldssomewhere, like we’re passing it down when rendering related resources, or we’re using the source resource when determining default fields instead of the destination resource. My instinct is a problem somewhere in the serializer.MartinVolerich
I found where the problem lies (for this case).
The situation is that I am including a related resource (in this case “Product”) in the GET and relying on the public of default_fields set for that resource.
If I set the default_fields for the main “base” resource (in my case “Survey”) in the base_route, then the included resource isn’t queried for its fields.
However if I set the default_fields for the main “base” resource in the resource module itself (inside the json_api block), then the other related resources is asked for it’s fields.
The problem is due to the logic at line 675 of the AshJsonApi.Serializer where fields is determined to be one of three lists.
fields =
Map.get(request.fields, resource) || Map.get(request.route, :default_fields) ||
default_attributes(resource)
If I manually swap the second and third parts then the default_fields on the route itself isn’t used when there are default fields set for the resource. And of course default_attributes has logic that will look to the explicit default_fields or the public attributes.
So a workaround is to just set the fields to be used as defaults in the resource and not in the route (in this case), but I’d be interested to hear what approach makes most sense.
FWIW, I’ll also post this in the issues list for the project.
Thanks
Martin
zachdaniel
Ah, right you are. This is a simple fix, which is that we should only be using the default fields from the route for the top level resource, not for included resources.
zachdaniel
great sleuthing! Thank you for finding this