Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2518

IdentityMap isn't cleared between requests

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.11
    • Affects Version/s: None
    • Component/s: None
    • None

      Hi there,

      TLTR: I run into a weird issue with Identity Map : it seems it doesn't get cleared.

      In a simple way : I have a Post model, and a Comment model, linked in a one2many way.

      When I update a Post, I get {:comments=>["n'est pas valide"]} error. Weird, the post doesn't have comments, and comments are not involved in this action.
      I found that in another page I use @post.comments.build to create a form. And then, it populates IdentityMap with this blank comment. And going to update this post in another page (different controller, different action), the blank comment is still there and keeps me from updating.

      When I add Mongoid::IdentityMap.clear just before the Post.find([...]), it works.

      As the issue is quite recent (3.0.10 I guess, not sure, but quite probable), I suspect @c63140b8 to be blamed. (related to MONGOID-2445)

      The issue doesn't appear on dev, only on prod : Passenger, multiple requests run on the same process. Fun fact, if I wait enough, I get a new process and the error disappears until the corresponding page doing @post.comments.build for the same @post is called by this process.

      [in the example, the update is blocked because of validations in Comment. The error appears on several other places, and in one other case, there is no validation and blank objects are silently added on their one]

            Assignee:
            Unassigned Unassigned
            Reporter:
            maximeg Maxime Garcia
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: