Skip to content

Different field lists are not considered when caching #2359

Open
@marselmustafin

Description

@marselmustafin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions