Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different field lists are not considered when caching #2359

Open
marselmustafin opened this issue Oct 12, 2019 · 0 comments
Open

Different field lists are not considered when caching #2359

marselmustafin opened this issue Oct 12, 2019 · 0 comments

Comments

@marselmustafin
Copy link

marselmustafin commented Oct 12, 2019

Expected behavior vs actual behavior

I have 2 following Rails actions:

def index
  render jsonapi: bonuses,
         include: [:sender, comments: :sender],
         fields: { users: [:full_name] }
end
def index
  render jsonapi: users
end

Caching is enabled in environment config:

config.action_controller.perform_caching = true
config.cache_store = :memory_store

Fragment of response from first action:

...

  "included": [
    {
      "id": "12",
      "type": "users",
      "attributes": {
        "full-name": "Marsel Mustafin"
      }
    },

...

Expected behaviour

Response from second action contains full list of fields defined in corresponding serializer:

{
  "data": [
    {
      "id": "12",
      "type": "users",
      "attributes": {
        "email": "[email protected]",
        "username": "marsel_mustafin",
        "full-name": "Marsel Mustafin",
        ...
      }
    },
...

Actual behaviour

Response from second action contains only full-name attribute in user objects:

{
  "data": [
    {
      "id": "12",
      "type": "users",
      "attributes": {
        "full-name": "Marsel Mustafin"
      }
    },
...

Environment

ActiveModelSerializers Version:
0.10.10

Output of ruby -e "puts RUBY_DESCRIPTION":
ruby 2.5.6p201 (2019-08-28 revision 67796) [x86_64-darwin17]

OS Type & Version:
MacOS 10.13.6

Integrated application and version:
Rails 5.1.6.2

Additonal helpful information

This behaviour is actual for other adapter types. Probably the best solution to fix that is to include fields list in cache key, to make object from each action be cached separately. If you ok with this idea, pls let me know and I'll try to provide PR with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant