Skip to content

Use proper check in acceptForeignKey()#3994

Merged
greg0ire merged 1 commit intodoctrine:2.10.xfrom
greg0ire:check-for-alter-support-fk
May 7, 2020
Merged

Use proper check in acceptForeignKey()#3994
greg0ire merged 1 commit intodoctrine:2.10.xfrom
greg0ire:check-for-alter-support-fk

Conversation

@greg0ire
Copy link
Member

@greg0ire greg0ire commented May 5, 2020

Q A
Type bug/feature/improvement
BC Break no
Fixed issues #3990

Summary

Checking that the platform supports foreign key is not the right case
here, because we should check if we can create them by themselves, after
the table is created. It is not the case for Sqlite.

Closes #3990

How can I test this?

composer config repositories.greg0ire vcs https://github.com/greg0ire/doctrine-dbal
composer require doctrine/dbal "dev-check-for-alter-support as 2.10.2"

@greg0ire greg0ire requested review from beberlei and morozov May 5, 2020 17:56
@greg0ire greg0ire added the Bug label May 5, 2020
@greg0ire

This comment has been minimized.

@greg0ire greg0ire force-pushed the check-for-alter-support-fk branch from 754e607 to e615ecf Compare May 5, 2020 17:58
}

/**
* @doesNotPerformAssertions
Copy link
Member

Choose a reason for hiding this comment

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

Just a note: @doesNotPerformAssertions also disregards coverage (conscious decision on PHPUnit's side). The recommended way to test that an exception hasn't been thrown is calling $this->addToAssertionCount(1) after the method that throws exceptions.

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL

Copy link
Member

@lcobucci lcobucci May 5, 2020

Choose a reason for hiding this comment

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

@greg0ire sebastianbergmann/phpunit#3348 (and I didn't send the PR to fix the docs since I got no confirmation 😆)

Copy link
Member

Choose a reason for hiding this comment

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

I'm really confused about having @doesNotPerformAssertions here. Is the only outcome of actions in the test scenario is not having an exception thrown? I would understand such expectations in a validation scenario (no exception means “valid”) but not here.

Copy link
Member Author

@greg0ire greg0ire May 5, 2020

Choose a reason for hiding this comment

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

@morozov my goal here was to have a failing test for an existing bug, I'm not really trying to assert anything, I want to fix a crash, and make sure it does not come back. Tell me if this file is not the right place for that (since it is in Functional, it might not be, but I'm not sure where I should put this). For PHPUnit I would put that kind of test here: For PHPUnit I would put it here: https://github.com/sebastianbergmann/phpunit/tree/master/tests/end-to-end/regression/GitHub

For DBAL… I have no clue. Please help.

Copy link
Member

Choose a reason for hiding this comment

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

I want to fix a crash, and make sure it does not come back.

IMO, the purpose of a test is to ensure that the code works, not that it doesn't crash. I.e. should be worded in terms of assertions against produced results.

How do you know that just the absence of failure is enough in the reported case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this is what is complained about… they are not complaining that the fk does not get created properly for instance.

Anyway, I started by asserting that the generated SQL contains something about foreign key, but then I thought that even that might not work so I executed the SQL and asserted that there is a foreign key defined on it, tell me if I went overboard.

Copy link
Member

Choose a reason for hiding this comment

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

Because this is what is complained about… they are not complaining that the fk does not get created properly for instance.

I don't think this is the right mindset. But I believe we're on the same page now.

[…] tell me if I went overboard

The approach looks fine. The only question is, is this case is platform-specific or we can move it into a platform-independent suite and get covered on all platforms. The fact that people tend to write platform-specific tests because they experience issues using a given platform is the primary reason why we have inconsistency in platform support.

}

public function testCreatingATableWithAForeignKey() : void
{
Copy link
Member Author

Choose a reason for hiding this comment

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

Few tests here have a guard clause about sqlite3, should I add one?

Copy link
Member

@morozov morozov May 6, 2020

Choose a reason for hiding this comment

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

Is there anything specific to SQLite in this scenario? If yes, then I think the setup of the functional platform-specific test should require the corresponding platform to be active.

Otherwise, the test should be part of a platform-independent suite.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is platform independent, and I'm not sure what a platform-independent suite is. I moved it to a file that inherits from DbalFunctionTestCase, let's see how this pans out. My only doubt is about the foreign key name, I have no idea what computes it and if it will be the same for every platform.

@greg0ire greg0ire added this to the 2.10.3 milestone May 6, 2020
@greg0ire greg0ire force-pushed the check-for-alter-support-fk branch 3 times, most recently from 86eea63 to fe17629 Compare May 6, 2020 17:31
@greg0ire
Copy link
Member Author

greg0ire commented May 6, 2020

Just pushed a version with a way, way less specific assertion.

@greg0ire
Copy link
Member Author

greg0ire commented May 6, 2020

@morozov any idea why it fails for IBM DB2 and only for that RDBMS?

@morozov
Copy link
Member

morozov commented May 6, 2020

[…] any idea why it fails for IBM DB2 and only for that RDBMS?

I cannot check it right now. It's fine to mark it incomplete for DB2 and fix later but I think you'll need the @beberlei’s approval to get it merged.

@morozov
Copy link
Member

morozov commented May 6, 2020

Well, actually, the problem seems to be in the case-sensitivity of DB2 when using quoted names.

This is what the SQL creating the tables looks like (note that one name is quoted and the other isn't):

CREATE TABLE referenced (id INTEGER NOT NULL, PRIMARY KEY(id))
CREATE TABLE "referencing" (referenced_id INTEGER NOT NULL)
-- ...
ALTER TABLE "referencing" ADD CONSTRAINT FK_E844F4C85A38C91 FOREIGN KEY (referenced_id) REFERENCES referenced (id)

And then how the FK is selected:

WHERE fk.TABNAME = UPPER(" . $table . ')

I don't think that quoting object names by default on DB2 or Oracle is the right thing to do, so it's definitely a bug in DBAL.

And this is why it's quoted:

@greg0ire
Copy link
Member Author

greg0ire commented May 6, 2020

Ok, I'll just pick another name for this PR I guess! Thanks a lot for the investigation.

Checking that the platform supports foreign key is not the right case
here, because we should check if we can create them by themselves, after
the table is created. It is not the case for Sqlite.

Closes doctrine#3990
@greg0ire greg0ire force-pushed the check-for-alter-support-fk branch from fe17629 to f0c1af4 Compare May 6, 2020 21:16
@greg0ire
Copy link
Member Author

greg0ire commented May 7, 2020

The tests that fails is unrelated (and seems time based)

@greg0ire greg0ire closed this May 7, 2020
@greg0ire greg0ire reopened this May 7, 2020
@greg0ire greg0ire merged commit f20ba14 into doctrine:2.10.x May 7, 2020
@greg0ire greg0ire deleted the check-for-alter-support-fk branch May 7, 2020 07:07
@greg0ire greg0ire self-assigned this May 7, 2020
greg0ire added a commit to greg0ire/symfony that referenced this pull request May 7, 2020
This reverts commit d1953d6.
doctrine/dbal has been fixed, see doctrine/dbal#3994
nicolas-grekas added a commit to symfony/symfony that referenced this pull request May 8, 2020
…ire)

This PR was squashed before being merged into the 3.4 branch.

Discussion
----------

Remove patches for Doctrine bugs and deprecations

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | n/a
| License       | MIT
| Doc PR        | n/a

This PR removes patches put in place because of a bug fixed in doctrine/dbal#3994, and because of deprecations addressed in doctrine/orm#7953

Commits
-------

2f305cd Remove patches for Doctrine bugs and deprecations
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Symfony CI red after "[GH-1204] Add full support for foreign key constraints in SQLite Platform and Schema"

4 participants