Ruby on Rails Saturday, June 30, 2018

> On Jun 29, 2018, at 11:17 PM, Frederick Cheung <frederick.cheung@gmail.com> wrote:
>
> On Thursday, June 28, 2018 at 2:13:31 AM UTC+1, Phil wrote:
>> This is odd... I have a few models that after some time just start doing SELECT "my_tablemy_belongs_to_table".* sort of thing. (Almost like it is trying to reference a join table, but missing a _ between the table names.)
>>
>> In other words, things work for hours, days or weeks then suddenly goes from SELECT "my_table".* to SELECT "my_tablemy_belongs_to_table".*
>
> There are a few activerecord settings (table_name, table_name_prefix maybe some others) that could do this. Might these be getting changed by accident (perhaps because your model has a method whose name clashes with an active record method) ?
>
> Fred
>
>>
>> The associated FROM clause also changes to match. Hundreds of exceptions per minute then ensue and all heck breaks loose. ;')
>>
>> I perhaps am running into a namespace issue or something(?)... how does a model get triggered into changing it's associated table name in runtime? Our temp fix it to just restart the service/app but that's obviously not sustainable. We had to do it several times today.
>>
>> Thoughts?
>>
>> ruby 2.5.0p21 (2018-02-18 revision 62472) [x86_64-linux]
>> rails 5.1.6
>> pg 1.0.0
>>
>> Thanks!
>>
>>
>> Phil

Thank you Fred and Colin.

Somehow table_name seems to be getting set to something else... I can simulate how it breaks but I don't know where/why it is breaking in the production code...

>> UserAccount.table_name = "blah"
=> "blah"
>> UserAccount.first
Traceback (most recent call last):
1: from (irb):2
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "blah" does not exist
LINE 1: SELECT "blah".* FROM "blah" ORDER BY "blah"."id" ASC LIMIT ...
^
: SELECT "blah".* FROM "blah" ORDER BY "blah"."id" ASC LIMIT $1)


Something in Rails 5.1.x is appending to 'table_name' in the model during some condition?

I can't easily reproduce. I don't see anywhere in the code where I'm operating on table_name directly.

(still digging, I hope everyone is having a good Saturday, btw :')


Phil

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/066091BE-E396-4E3A-BDDC-DE0DECD24476%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment