Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixed commit order#7660

Closed
tomaszgaw wants to merge 167 commits into
doctrine:2.6from
tomaszgaw:fix-commit-order
Closed

Fixed commit order#7660
tomaszgaw wants to merge 167 commits into
doctrine:2.6from
tomaszgaw:fix-commit-order

Conversation

@tomaszgaw
Copy link
Copy Markdown

@tomaszgaw tomaszgaw commented Mar 27, 2019

Fixes visit method of CommitOrderCalculator.

Without the fix the insertion order is not properly calculated when a cycle within the graph involves more than 2 classes, leading to a violation of not null constraints on the owning side of ManyToOne relation.

With the fix when a cycle is detected a node is revisited ignoring edges of weight 0.

@SenseException
Copy link
Copy Markdown
Member

Can you please cover your changes with tests?

I'm also not sure yet if this introduces changes in the behaviour on first look.

@tomaszgaw
Copy link
Copy Markdown
Author

The test I added passes when runs against the fixed code and fails when runs against the original code.

Comment thread tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php
@greg0ire
Copy link
Copy Markdown
Member

greg0ire commented Apr 4, 2019

There should be only one commit, the test does not make sense without the code, and the code should not come without tests. Please improve the commit message to make as interesting as the pull request text.

* @param \stdClass $vertex
*/
private function visit($vertex)
private function visit($vertex, $minimumWeight = 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This branch requires 7.2, you can use a type hint:

Suggested change
private function visit($vertex, $minimumWeight = 0)
private function visit($vertex, int $minimumWeight = 0)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I applied the suggested change in the last (squashed) commit. Thank you.

@beberlei beberlei modified the milestones: 2.7.4, 2.7.5 Oct 11, 2020
beberlei and others added 4 commits October 11, 2020 19:14
* Update working-with-indexed-associations.rst

Fixing broken link

* Update docs/en/tutorials/working-with-indexed-associations.rst

Co-authored-by: Claudio Zizza <[email protected]>

Co-authored-by: Claudio Zizza <[email protected]>
- Some uppercase letters were used in the middle of sentence
- Some dots were missing
- There was two sentences with wrong or missing words
@greg0ire
Copy link
Copy Markdown
Member

Both commits explain what they fix, but not how. Please include the explanation and follow the guidelines at https://www.doctrine-project.org/contribute/index.html#working-on-topic-branches

greg0ire and others added 8 commits October 28, 2020 11:14
* Use a classname that exists

Doctrine\ORM\Mapping\TableGenerator does not exist, only
Doctrine\ORM\Id\TableGenerator does.

* Upgrade doctrine/coding-standard

That library has a dependency on another library that requires composer
plugin API v1. Updating both libs allow to use Composer v2.

* Account for doctrine/reflection deprecation
* Update outdated doc parts

- The cache implementation moved from `Common` to `doctrine/cache`
- APCu is mor appropiate nowadays I guess
- AbstractQuery::useResultCache() is deprecated since 2.7

* Fix wrong argument

* Fix wrong arguments and remove useless line
* Move PHPUnit runs from Travis to Github Actions

This removes all artifacts used for TravisCI testing and replaces them
with the existing infrastructure for Github Actions from DBAL component.

In addition some test changes were needed and triggered larger Coding
Style cleanups in 3 test files.

* Remove composer.lock and improve naming in CI workflow.
* Revert to whitelist

coverage requires PHPunit 9, and we don't have that yet.

* Upgrade to PHPUnit 8

This unlocks PCOV usage for coverage

* Upload coverage files to Codecov
…8329)

This fixes a regression from 099c5b4.
Without the fix, "where part" in SQL is generated with incorrect aliases.
See doctrine#8229 (comment).
This fixes a commit order when persisting many entities with cyclic
associations within one flush. Before the fix, when multiple cycles
were presented in the precedence graph and more than two classes
existed in within a cycle the calculated commit order was likely to be
wrong, resulting in not null constraint violation when saving to
a database. An example of such situation is provided in
CommitOrderCalculatorTest::testCommitOrdering4() - this is a test case
with won’t pass without the introduced fix.

Prior to the fix the weight of an edge in a class precedence graph was
compared only to the weight of the subsequent edges. Therefore, in case
of cycles containing more than two classes the result was
unpredictable. The fixed code uses also the weight of further nodes in
the precedence graph. It is achieved by adding minimum weight argument
to the visitor function of CommitOrderCalulator – edges having weight
below the minimum weight are ignored. The minimum weight is increased
each time a node is revisited, i. e. a cycle is detected. It guarantees
that edges of highest priority representing not nullable relationships
are processed first.
It may happen that an entity class A has multiple many-to-one
associations with the same target entity B. These associations may
differ in “nullable” parameter. In such situation
CommitOrderCalculator::addDependency() is called multiple times for the
same pair of $fromHash and $toHash, with different value of $weight
argument. Before the fix the subsequent call to
CommitOrderCalculator::addDependency() for the same $fromHash and
$toHash overrode $weight set at the previous call. It caused
unpredictable commit order of entities which resulted in not null
constraint violation when saving to a database.

Fixed code preserves the highest value of weight argument. If at
subsequent call the weight is lower than previously established weight
the addition of edge to the dependency list is skipped.
@greg0ire
Copy link
Copy Markdown
Member

Closing in favor of #8349

@greg0ire greg0ire closed this Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.