This project is archived and is in readonly mode.

#4632 ✓stale

Query inside of ActiveRecord Observer generated incorrect SQL

Reported by cilcoder | May 17th, 2010 @ 11:33 PM

The Problem

For a model class, 'NodeArgument', I am calling NodeArgument.all inside of an observer for the NodeArgument model and instead of returning all NodeArguments, it is only returning a subset of them.

The Setup:

Model Classes:

has_many :node_arguments

Node Arguments

belongs_to :node

An Observer with after_correct.

Triggering the issue

I have a Node object and call @node.node_arguments.find_or_create_by_name(...)
This successfully creates the Node Argument and triggers the observer's after_create method.


In the observer I am using NodeArgument.all. From the log, I can see that they query being generated has a where clause of node_id = .

Expected Result

I would expect the NodeArgument.all method to behave like normal. It seems to be a reentrancy problem to me.

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar October 7th, 2010 @ 05:21 AM

    • Tag changed from activerecord associations, aciverecord, find, observers to aciverecord, activerecord, associations, find, observers
  • David Trasbo

    David Trasbo October 8th, 2010 @ 09:00 AM

    • State changed from “new” to “incomplete”
    • Importance changed from “” to “Low”

    Please provide a patch with a failing test and/or a fix.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:58 PM

    • State changed from “incomplete” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:58 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket