Coder Social home page Coder Social logo

Comments (24)

matthewford avatar matthewford commented on July 20, 2024

My statemachine: https://github.com/alphagov/whitehall/blob/postgresql/app/models/edition/workflow.rb

from transitions.

matthewford avatar matthewford commented on July 20, 2024

Specifically when using postgresql

from transitions.

troessner avatar troessner commented on July 20, 2024

First of all, why are you doing:

include ::Transitions
include ActiveRecord::Transitions

?

I think

include ActiveModel::Transitions

should be ok.

Second, "specifically" means "not on mysql" in this case?
I am asking because we had quite a problems that occured using postgresql, but not mysql.

from transitions.

matthewford avatar matthewford commented on July 20, 2024

Yes, with our mysql branch I'm seeing no issues.

from transitions.

troessner avatar troessner commented on July 20, 2024

Interesting. I'll look into this but i can't promise anything until the weekend because of work. @barelyknown are you free to look into this?

from transitions.

matthewford avatar matthewford commented on July 20, 2024

Cheers, No rush.

from transitions.

barelyknown avatar barelyknown commented on July 20, 2024

I may be able to take a look tomorrow morning.

from transitions.

matthewford avatar matthewford commented on July 20, 2024

More info: apparently we see this on <3.2 on Mysql as well so it might be an active model issue

from transitions.

troessner avatar troessner commented on July 20, 2024

@barelyknown any updates on this?

from transitions.

barelyknown avatar barelyknown commented on July 20, 2024

I haven't looked into it yet. Totally forgot after the initial email thread.

from transitions.

dbelwood avatar dbelwood commented on July 20, 2024

FWIW, I'm getting the same error with this line -
Subscription.select("id, user_id").where("updated_at >= ?", Time.at(Benchprep::Commands::UpdateUserTotalRevenue.get_last_run_at).to_formatted_s(:db)).order(:id)

But not this -
Subscription.select("id, user_id, state").where("updated_at >= ?", Time.at(Benchprep::Commands::UpdateUserTotalRevenue.get_last_run_at).to_formatted_s(:db)).order(:id)

The lack of a state column seems to be the culprit. The second line works in 0.1.3, but not 0.1.9

from transitions.

troessner avatar troessner commented on July 20, 2024

Sorry guys for having let this issue remain open so long. I'll try to take care of it asap.
But first, can we quickly gather what we know about this issue?

So am I getting this right @dbelwood and @matthewford :

  • The issue appears only with AR < 3.2
  • Happens on mysql / postgresql
  • Does not appear with 0.1.3, but with 0.1.9 it does

Can you confirm this?

from transitions.

matthewford avatar matthewford commented on July 20, 2024

I haven't tried on 0.1.3, but I can confirm the other two

from transitions.

troessner avatar troessner commented on July 20, 2024

Thanks, I will definitely look into this this week.

from transitions.

fairchild avatar fairchild commented on July 20, 2024

fyi, i had the same error (running postgresql) and eliminated the error by removing the ranked_model gem that I was also using. I did not dig in enough to figure out why, but this might help figure out why an error is being thrown.

from transitions.

troessner avatar troessner commented on July 20, 2024

Alright guys,

I need a little help to reproduce this problem. Please have a look at this feature branch i just created:

master...issue_95

It uses:

  • a custom select without the state column
  • mysql
  • activerecord 3.1.0:

( $ (issue_95)) bundle list | grep -i record
activerecord (3.1.0)

So I'd have expected the associated test to fail. Only it doesn't.

How can I reproduce the behaviour you reported?

@fairchild thanks for the additional info, but I think I'll try to reproduce the less complicated set up..:)

from transitions.

corroded avatar corroded commented on July 20, 2024

We have also experienced this in 0.1.5 (I upgrade to 0.1.9) hoping it fixes it but the issue still occurs. We also notice that it complains about the state attribute missing:

1.9.3 (main):0 > Customer.select :id
  Customer Load (0.4ms)  SELECT id FROM "customers"
=> [#<Customer id: 1>, #<Customer id: 6454>, #<Customer id: 6455>, #<Customer id: 6456>, #<Customer id: 6457>, #<Customer id: 6458>, #<Customer id: 6459>, #<Customer id: 6460>, #<Customer id: 6461>, #<Customer id: 6462>, #<Customer id: 6463>, #<Customer id: 6464>, #<Customer id: 6465>, #<Customer id: 6466>, #<Customer id: 6467>, #<Customer id: 12906>, #<Customer id: 12907>]
1.9.3 (main):0 > cc = _
=> [#<Customer id: 1>, #<Customer id: 6454>, #<Customer id: 6455>, #<Customer id: 6456>, #<Customer id: 6457>, #<Customer id: 6458>, #<Customer id: 6459>, #<Customer id: 6460>, #<Customer id: 6461>, #<Customer id: 6462>, #<Customer id: 6463>, #<Customer id: 6464>, #<Customer id: 6465>, #<Customer id: 6466>, #<Customer id: 6467>, #<Customer id: 12906>, #<Customer id: 12907>]
1.9.3 (main):0 > cc.inspect
=> "[#<Customer id: 1>, #<Customer id: 6454>, #<Customer id: 6455>, #<Customer id: 6456>, #<Customer id: 6457>, #<Customer id: 6458>, #<Customer id: 6459>, #<Customer id: 6460>, #<Customer id: 6461>, #<Customer id: 6462>, #<Customer id: 6463>, #<Customer id: 6464>, #<Customer id: 6465>, #<Customer id: 6466>, #<Customer id: 6467>, #<Customer id: 12906>, #<Customer id: 12907>]"

1.9.3 (main):0 > jj = Job.select :id
  Job Load (0.3ms)  SELECT id FROM "jobs"
=> #<ActiveRecord::Relation:0x3fe9da7a31b4>
1.9.3 (main):0 > jj.inspect
  Job Load (0.5ms)  SELECT id FROM "jobs"
ActiveModel::MissingAttributeError: missing attribute: state
from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/transitions-0.1.5/lib/active_model/transitions.rb:66:in `set_initial_state'
1.9.3 (main):0 > jj.map
  Job Load (0.4ms)  SELECT id FROM "jobs"
  Job Load (0.2ms)  SELECT id FROM "jobs"
ActiveModel::MissingAttributeError: missing attribute: state
from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/transitions-0.1.5/lib/active_model/transitions.rb:66:in `set_initial_state'
1.9.3 (main):0 > jj.first
  Job Load (0.4ms)  SELECT id FROM "jobs" LIMIT 1
ActiveModel::MissingAttributeError: missing attribute: state
from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/transitions-0.1.5/lib/active_model/transitions.rb:66:in `set_initial_state'

1.9.3 (main):0 > ii = Invoice.select :id
  Invoice Load (0.4ms)  SELECT id FROM "invoices"
=> #<ActiveRecord::Relation:0x3fe9daeecbb4>
1.9.3 (main):0 > ii.inspect
  Invoice Load (0.3ms)  SELECT id FROM "invoices"
ActiveModel::MissingAttributeError: missing attribute: state
from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/transitions-0.1.5/lib/active_model/transitions.rb:66:in `set_initial_state'

as you can see from above, we are trying to select distinct ids from jobs. It failed for us so we tried it on other models. From the console logs above, you can see that it works perfectly fine on customers, but fails on jobs and invoices. Jobs and invoices both have transitions, while customer is a plain AR model.

when we try any selector for Job or Invoice (using either first or last, we get that MissingAttributeError. One thing to note that might help:

1.9.3 (main):0 > jj.pluck 1
   (0.4ms)  SELECT id, 1 FROM "jobs"
=> [1, 2, 3, 4, 5, 7, 17]

Don't know why pluck gives us that while map, first or last doesn't. Examples above are from 0.1.5. But we also tried 0.1.9:

1.9.3p194 :002 > Job.select :id
Creating scope :all. Overwriting existing method Job.all.
  Job Load (0.4ms)  SELECT id FROM "jobs"
(Object doesn't support #inspect)
 =>
1.9.3p194 :003 > Job.select(:id).first
  Job Load (0.3ms)  SELECT id FROM "jobs" LIMIT 1
NoMethodError: undefined method `to_sym' for nil:NilClass
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/transitions-0.1.9/lib/active_model/transitions.rb:91:in `set_initial_state'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `_run__2958716729451653381__initialize__4056324975497312426__callbacks'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_initialize_callbacks'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/base.rb:523:in `init_with'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/inheritance.rb:68:in `instantiate'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/querying.rb:38:in `block (2 levels) in find_by_sql'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/querying.rb:38:in `collect!'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/querying.rb:38:in `block in find_by_sql'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/explain.rb:40:in `logging_query_plan'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/querying.rb:37:in `find_by_sql'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/newrelic_rpm-3.6.5.130/lib/new_relic/agent/method_tracer.rb:518:in `block in find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/newrelic_rpm-3.6.5.130/lib/new_relic/agent/method_tracer.rb:268:in `trace_execution_scoped'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/newrelic_rpm-3.6.5.130/lib/new_relic/agent/method_tracer.rb:513:in `find_by_sql_with_trace_ActiveRecord_self_name_find_by_sql'
    from /Users/dev/.rvm/gems/ruby-1.9.3-p194@spanner/gems/activerecord-3.2.11/lib/active_record/relation.rb:171:in `exec_queries'

Same result with map, last and [0]. BUT!

1.9.3p194 :018 >   Job.select(:id).pluck 1
   (0.3ms)  SELECT id, 1 FROM "jobs"
 => [1, 2, 3, 4, 5, 7, 17]

I hope those logs I pasted aren't just jargon and will actually help in solving the problem.

I might try checking out the feature branch either tonight or tomorrow and see how it goes.

from transitions.

troessner avatar troessner commented on July 20, 2024

Ah, thanks a lot, got it!

bdc1040

-> Ok, i can reproduce this now, I'll fix this a.s.a.p

from transitions.

corroded avatar corroded commented on July 20, 2024

sweet! Thanks! hopefully it's not a major one...

from transitions.

corroded avatar corroded commented on July 20, 2024

hi @troessner, just a question if there's a fix already for this? Thanks!

from transitions.

troessner avatar troessner commented on July 20, 2024

I just released 0.1.10 which fixes this problem as far as I can see - please try it out and let me know if that works for you.
If not, feel free to re-open this issue.

from transitions.

troessner avatar troessner commented on July 20, 2024

Sooooo, any feedback, guys?

from transitions.

matthewford avatar matthewford commented on July 20, 2024

Hi Timo,

I'll see if I can replicate the issue with the patch on Monday, thanks for
the fix.

Matthew Ford

Director of Bit Zesty

T: +44 (0)2071250160

This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify Bit Zesty
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system. Bit Zesty does not accept liability
for any errors or omissions in the contents of this message, which arise as
a result of e-mail transmission. Opinions expressed in this email are those
of Matthew Ford, and do not necessarily reflect those of Bit Zesty.

Bit Zesty Ltd, a company incorporated in England with registered company
number 06883289.

On 9 August 2013 12:00, Timo RรถรŸner [email protected] wrote:

Sooooo, any feedback, guys?

โ€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/95#issuecomment-22387752
.

from transitions.

corroded avatar corroded commented on July 20, 2024

sorry haven't tried it yet in our code since it wasn't scheduled. We will try it out on monday and give some feedback. Thanks for this!

from transitions.

Related Issues (20)

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.