Giter Club home page Giter Club logo

Comments (25)

zachaysan avatar zachaysan commented on June 27, 2024 1

Is this still an issue in Rails 5.1? I'm going to help keep this project maintained and I want to fix what's broken and make sure we can support Rails 5.2 now that it is out.

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024 1

Sounds fair. It is going to take me a little longer to reproduce again as I'm fixing some conflicts in the branch I was working in. I'll re-open the issue when it gets to that point.

from activerecord-hierarchical_query.

thooams avatar thooams commented on June 27, 2024

It's start_with method which generates an error. I don't know why.
Only variable $2 (LIMIT) is taken into account.

from activerecord-hierarchical_query.

thooams avatar thooams commented on June 27, 2024

Try to replace start_with(id: id) by start_with(YourModel.find(id)) or start_with(self)

from activerecord-hierarchical_query.

mkamensky avatar mkamensky commented on June 27, 2024

I see the same problem. If I try to give the object as an argument to start_with, it ignores the condition

from activerecord-hierarchical_query.

mkamensky avatar mkamensky commented on June 27, 2024

It appears that when chaining with other queries, the argument list gets replaced

from activerecord-hierarchical_query.

mkamensky avatar mkamensky commented on June 27, 2024

A workaround similar to the one mention in rails/rails#20077 (comment) worked for me

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

@zachaysan I would suspect so. One of the reasons I'm still stuck on Rails 4.2 is because I couldn't upgrade activerecord-hierarchical_query without issues like this when attempting a Rails 5 upgrade, so if you're looking to help fix and maintain, I would be happy to help you and do testing and try a Rails 5 upgrade again. Not sure on the time frame though due to work responsibilities.

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

Great @xtagon I don't want you to waste time so if you could just give me a detailed, but austere way of replicating the bug I'll try to handle as soon as possible.

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

@zachaysan I'll have to pull my Rails 5 upgrade branch and see if I can reproduce. There have been a lot of changes to my own app since I last tried the upgrade. I'll try to do it this weekend. Thanks so much for the help!

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

Hey @xtagon I'm going to close this issue. If you can re-produce in 1.1.0 let me know, but I'm currently unable to.

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

@zachaysan Just to let you know, I reproduced this on 1.1.0 and Rails 5.0, but this time when I changed start_with to use self instead of the model ID, it fixed it. Awesome!

Thanks again for everyone's help.

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

@xtagon Dang really? What happens if you do self.id?

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

If I pass the ID it has a prepared statement error like the one I originally shared. If I pass the model object it works. I think if I pass an array of multiple IDs it works too.

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

I'm trying to make sure it's not related to some id weirdness. Sometimes ids are strings in rails and sometimes they're integers.

What happens if you do this:

relation = self.class.join_recursive do |query|
  query.start_with(id: self.id).connect_by(parent_organization_id: :id)
end

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

Here is part of the code that I got the error from:

relation = self.class.join_recursive do |query|
      query.
        start_with(id: self.id) { select("0 depth") }.
        select(query.prior[:depth] + 1, start_with: false).
        connect_by(id: :parent_organization_id)
    end

It only causes an error if you do a where condition or similar later on this relation as described above. If you do a to_a directly on it it's fine. Replacing self.id with self fixes it too.

I didn't think of this before but I am using Postgres GUID strings as IDs if that helps.

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

Hmm. I'm going to bet that GUID is why I can't seem to replicate because I'm not currently using them and they're another tricky case of sometimes integer, sometimes string tomfoolery.

Are you able to clone the repo and run the tests? Could you create a failing tests with a GUID column? If you can do that I'll try to figure out the root cause.

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

I'll give it a shot.

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

All tests pass when I switch your test schema to use UUIDs. I even added a test case that looks as close as possible to the one in my app (I am not able to give access to my app's source unfortunately).

Very strange, I'm not sure why it won't reproduce.

xtagon@4ea5b6e

I made sure to use the Rails 5.0 gemfile too.

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

Hmmm. Are you using any weird default scopes or redefining any core methods?

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

I am using this soft deletion gem on the model, which adds a default scope for deleted_at IS NULL: https://rubygems.org/gems/soft_deletion

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

Sorry for the delay. Does disabling the gem do anything? I dislike uncertainty and spookiness in libraries so I'd like to figure out what is wrong.

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

Just tried that, it didn't seem to have an effect.

This is on Rails 5.0.0 - I'm going to be upgrading to 5.1 and then 5.2 soon-ish, maybe it was something that changed in Arel

from activerecord-hierarchical_query.

xtagon avatar xtagon commented on June 27, 2024

I'd like to figure out what is wrong too, but just to clarify I'm perfectly fine with the workaround of using the record instance -- it doesn't solve the mystery but it solves my use case

from activerecord-hierarchical_query.

zachaysan avatar zachaysan commented on June 27, 2024

Well if it is still an issue in 5.2 then I'm going to try to figure it out. Partially for my own interests. I want to be able to rely on this library in production and I generate some pretty abstract queries during a request cycle so this needs to be dependable.

from activerecord-hierarchical_query.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.