Skip to content

Conversation

mtsmfm
Copy link
Contributor

@mtsmfm mtsmfm commented Jan 10, 2017

Re-create #21233

eeac615 was reverted (127509c) because it breaks tests.


ref: 72c1557

context: #5523

Other Information

  • We must use authors fixture with author_addresses because of its foreign key constraint.
  • Tests require PostgreSQL >= 9.4.2 because it had a bug about ALTER CONSTRAINTS and fixed in 9.4.2.

@rails-bot
Copy link

r? @chancancode

(@rails-bot has picked a reviewer for you, use r? to override)

@yahonda
Copy link
Member

yahonda commented Feb 7, 2017

Let me add some comment for this pull request.

There was a pull request #21233 which had merged and reverted back due to regressions. I believe this pull request addresses regression by loading necessary :author_address fixtures.

@mtsmfm mtsmfm force-pushed the disable-referential-integrity-without-superuser-privilege-take-2 branch from 656edb7 to 8aba178 Compare March 13, 2017 10:50
@mtsmfm
Copy link
Contributor Author

mtsmfm commented Mar 15, 2017

Sorry, test is failing after rebase 😢
I'll investigate and fix it.

@mtsmfm mtsmfm force-pushed the disable-referential-integrity-without-superuser-privilege-take-2 branch from 8aba178 to 1829d0d Compare March 15, 2017 15:23
@mtsmfm
Copy link
Contributor Author

mtsmfm commented Mar 15, 2017

Sorry, test is failing after rebase
I'll investigate and fix it.

https://travis-ci.org/rails/rails/jobs/210515444

1) Failure:
AssociationProxyTest#test_save_on_parent_saves_children [/home/travis/build/rails/rails/activerecord/test/cases/associations_test.rb:185]:
Expected: 1
  Actual: 2

I found the cause.
It is not related to this PR.
#28426 will fix it.

@mtsmfm mtsmfm force-pushed the disable-referential-integrity-without-superuser-privilege-take-2 branch 2 times, most recently from 7f9d22d to f4ada34 Compare March 16, 2017 08:44
@ericboehs
Copy link

ericboehs commented Mar 20, 2017

It looks like the tests are passing and this pull request is ready for another review?

I'm hopeful this will get merged for 5.1 as it is needed for Heroku CI to work. <3

Edit: Annnd RC1 just landed. :(

@mtsmfm
Copy link
Contributor Author

mtsmfm commented Mar 21, 2017

@rafaelfranca @chancancode Could you review this pr?

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. I just reviewed it. Could you made the change and rebase?

@@ -314,6 +314,12 @@ def supports_pgcrypto_uuid?
postgresql_version >= 90400
end

# PostgreSQL 9.4 introduces ALTER TABLE ... ALTER CONSTRAINT but it has a bug and fixed in 9.4.2
# https://www.postgresql.org/docs/9.4/static/release-9-4-2.html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this comment to inside the method? Otherwise it will show as documentation of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved and force pushed!

BTW, I followed the same way as supports_ranges? so it may not be intended.
I created another PR #28543.
Please close the PR if the comment is intended 😅

@mtsmfm mtsmfm force-pushed the disable-referential-integrity-without-superuser-privilege-take-2 branch from f4ada34 to b410c79 Compare March 23, 2017 11:21
mtsmfm added a commit to mtsmfm/rails that referenced this pull request Mar 23, 2017
Because this comment is not document for `supports_ranges?`

ref: rails#27636 (comment)
@mtsmfm
Copy link
Contributor Author

mtsmfm commented Mar 26, 2017

https://travis-ci.org/rails/rails/builds/214205098

ap, ac test is failed.
It isn't related to this pr.

I'll rebase and force push to restart test.

mtsmfm and others added 2 commits March 26, 2017 17:12
…eruser privileges (take 2)

Re-create rails#21233

eeac615 was reverted (127509c) because it breaks tests.

----------------

ref: 72c1557

- We must use `authors` fixture with `author_addresses` because of its foreign key constraint.
- Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
@mtsmfm mtsmfm force-pushed the disable-referential-integrity-without-superuser-privilege-take-2 branch from b410c79 to ef6391d Compare March 26, 2017 08:12
@mtsmfm
Copy link
Contributor Author

mtsmfm commented Mar 26, 2017

#27636 (comment)

@rafaelfranca I moved the comment and force pushed 😃

@rafaelfranca rafaelfranca merged commit c1faca6 into rails:master Mar 27, 2017
@ericboehs
Copy link

@rafaelfranca Forgive my ignorance here, but are changes to master now targeting 5.1.1? Instead of 5.1.0?

@rafaelfranca
Copy link
Member

5.2.0 actually. But I'll backport it to 5.1.0

rafaelfranca added a commit that referenced this pull request Mar 27, 2017
…ithout-superuser-privilege-take-2

Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges (take 2)
@rafaelfranca
Copy link
Member

Backported in 1ccd40e

@ericboehs
Copy link

That's great news! Thank you kindly.

y-yagi added a commit to y-yagi/rails that referenced this pull request Apr 3, 2017
@y-yagi y-yagi mentioned this pull request Apr 3, 2017
rafaelfranca added a commit that referenced this pull request Apr 26, 2017
…egrity-without-superuser-privilege-take-2"

This reverts commit 1ccd40e.

Fixes #28888

Referential actions other than the NO ACTION check cannot be deferred,
even if the constraint is declared deferrable.
@rafaelfranca
Copy link
Member

Reverted again in 2812694. Seems like referential actions other than the NO ACTION check cannot be deferred, even if the constraint is declared deferrable.

rafaelfranca added a commit that referenced this pull request Apr 26, 2017
…egrity-without-superuser-privilege-take-2"

This reverts commit c1faca6, reversing
changes made to 8c658a0.

See #27636 (comment)
yahonda added a commit to yahonda/rails that referenced this pull request Aug 22, 2017
`:authors` has a foreign key to `:author_addresses`.
If only `:authors` fixture loaded into the database which supports
foreign key and checks the existing data when enabling foreien keys
like Oracle, it raises the following error

`ORA-02298: cannot validate (ARUNIT.FK_RAILS_94423A17A3) - parent keys not found`

It is because there is no parent data exists in `author_addresses` table.

Here are how other database with foreign key support works:

- MySQL does not check the existing data when enabling foreign key by `foreign_key_checks=1`
https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_foreign_key_checks
> Setting foreign_key_checks to 1 does not trigger a scan of the existing table data. Therefore, rows added to the table while foreign_key_checks=0 will not be verified for consistency.

- PostgreSQL database itself has a feature to check existing data when
enabling foreign key and discussed at rails#27636, which is reverted.
@ASing0
Copy link

ASing0 commented Nov 9, 2022

If I understand this issue and fix correctly, you added a parameter so you can run tests with foreign keys, that normally require superuser privileges, without those privileges. If this is correct, (and I hope it is because I'm trying to run Rails tests on Azure Postgres, which does not allow superuser), would you kindly tell me where this parameter is and what to change it to?

@felixwatts
Copy link

Same question here

@zzak
Copy link
Member

zzak commented Oct 20, 2023

@felixwatts @ASing0 This is just a suggestion, but if you've hit a bug running the rails test suite, it's preferable to open a new ticket with a reproducible test case than comment asking for help on a 5 year old PR. Alternatively, you can ask as many questions you want on the discuss. 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants