-
-
Notifications
You must be signed in to change notification settings - Fork 725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make db timestamps nullable #5663
Conversation
The second version of the schema seems to only have indentation changes...? |
yes, but if you see the first commit you will see that the second commit removes the constraints on the timestamps which is what really matters in this PR. Basically, the constraints were there just not in db/schema 🙈 and this PR removes them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is confusing. I mean the situation, your commits are good (except maybe one typo?).
OFN v2 on Rails 3.2
# Migration
create_table :enterprises do |t|
...
t.timestamps
# Schema
create_table "enterprises", :force => true do |t|
...
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
...
# Result in the database:
created_at | timestamp without time zone | | not null |
updated_at | timestamp without time zone | | not null |
That's consistent and I guess it was the default with Rails 3 because most migrations don't specify null
.
OFN v3 on Rails 4.0
create_table "enterprises", :force => true do |t|
...
t.datetime "created_at"
t.datetime "updated_at"
...
# Result with db:reset:
created_at | timestamp without time zone | | |
updated_at | timestamp without time zone | | |
# Result with db:migrate from old database
created_at | timestamp without time zone | | not null |
updated_at | timestamp without time zone | | not null |
The reason is commit 7640c7b which changed the schema but not the database. So basically the first commit in this pull request is reverting that incomplete commit and the second commit is doing it properly.
Luis, it looks like you identified a problem with null: false
in the past.
Rails 4.2 has the default null: true
and it looks like our version of Rails 4.0 has that as well. Rails 5 will default to null: false
again which means that we should probably find out why timestamps are not set and then go back.
Deprecated add_timestamps and t.timestamps without passing the :null option. The default of null: true will change in Rails 5 to null: false.
https://guides.rubyonrails.org/4_2_release_notes.html#active-record-deprecations
That's right. I'm moving on with this solution until we find out what's the root cause. |
Hi @luisramos0 , I checked basic functionality around checkout issues:
Smoke tested the app. Found nothing unusual. Moving to ready to go. |
Make db timestamps nullable
Ultimately we want to revert this, right? The constraint should be there, and we don't want any records with NULL values in timestamp fields, as that might cause even worse problems? Or no? |
Some possible clues; suggesting a transaction rollback whilst saving a parent object (possibly due to another validation failure?) causing subsequent problems with child objects: |
Yes, we can revert this, it would be better to have the timestamps, I wonder if we will actually get empty timestamps. |
We're introducing a change that means theoretically any object can have |
Looking in Bugsnag at the errors and their timings, we can see these errors actually come in pairs, where the first error looks like this:
and the second error looks like this:
Going back to this comment: rails/rails#24219 (comment) I'd say it looks like the error we focussed on was a symptom and not the cause. My rough theory is: something goes wrong with shipping_rates part (callbacks hell?), then the transaction is rolled back in a disorderly manner, which causes the NULL values problem in associated objects (which are being updated as part of the same transaction). |
hmm, I see, that makes sense and, if correct, it's not good news... any idea what's the root cause and how to solve it? The only rollback/save code we have, I think, is in the payment
Is your logic/order of the pair "first and second" correct? It's a stack trace with "Caused by:". I'd say the order is the opposite. |
Hmmm... the first couple of pairs I looked at were in that order, but looking again it seems the order is random, it's the other way around in some cases. 😞 |
I've been checking those errors in Bugsnag and the issue seems to be that once the order was placed, the Seeing the number of failures and their timings, I think the user retrying many times, the order can be placed successfully, this step fails and the DB transaction is rolled back. Do we do any special treatment to the payment so that it gets rollback as well in Stripe @luisramos0 ? |
I wonder if set_default_ship_address is still within the same order workflow/payment transaction. Do you think that everything would have to be roll backed if that post checkout action fails? |
I need to play with locally to confirm it but by the backtrace, it looks like it.
This is why
And it seems that |
re that |
Do we want I'm 99% sure it's this call to |
Yes, I think that's what we want instead. Passing the timestamps columns as nil to |
Also I think Wait, it looks like You'd think they would have mentioned potentially breaking changes to commonly-used methods in the upgrade guide... 😒 |
given everything changes, I would just "reimplement" this bit of logic to whatever the Rails 4-way might be. I still think that we'll need to blacklist the two timestamps columns so we don't provide a value for them when updating the user or the customer objects' address. |
Interestingly this seems to only apply to ship_address and not bill_address... |
In that case we assign the address of the distributor I believe. It is done
somewhere in a decorator I think.
El dl., 29 de juny 2020, 19:14, Matt-Yorkley <[email protected]> va
escriure:
… In some cases ship_address is empty, because the shipping method is
pickup, right?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#5663 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAF2B2FMRICXAYNXTVHMBBDRZDDX7ANCNFSM4OF5OUDA>
.
|
I don't know why we didn't have any failing specs for this... |
I created an issue for the outstanding work discussed here: #5702 |
Oh 💩 . That's useful for Eugeni too. I'll let him know. |
Okay, so I think the reason we didn't get any failing specs before was the issue (mentioned earlier in this thread) where the migrations and the schema were not totally in sync because of some mistake in the upgrade branch. When we fixed that problem and made timestamps nullable at the same time, it covered up the loud failures associated with the underlying checkout/addresses problem. Making timestamps not-nullable again, but with the migrations and schema in sync gives a red build. |
What? Why?
Closes #5662
This makes the timestamps nullable for now, it will close 5662.
We can then investigate further and see why the timestamps are not being populated in some cases.
What should we test?
We can run a sanity check of the app.
Release notes
Changelog Category: Changed
Make timestamps nullable so the app doesnt blow up when they are not populated by raisl for some reason.