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

Skip to content

[DoctrineBridge] Fix LockStoreSchemaListener not working properly with iterable objects #54407

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

Closed
wants to merge 4 commits into from

Conversation

barton-webwings
Copy link
Contributor

@barton-webwings barton-webwings commented Mar 26, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? yes
Deprecations? no
Issues Fix #54406
License MIT

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.4" but it seems your PR description refers to branch "7.1 for features / 5.4, 6.4, or 7.0 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@MatTheCat
Copy link
Contributor

MatTheCat commented Mar 26, 2024

I think you can simply revert #50761:

  • ArrayIterator won’t work as expected when passed a traversable (this is why testPostGenerateSchemaWithInvalidLockStore passes: its iterator won’t yield anything. You can be sure because its generator uses $this while being static).
  • Exceptions thrown inside a generator will appear when calling valid or next, not current.
  • An exception thrown inside a generator would close it, even if caught when iterating; this could result in other stores being silently ignored.
  • LogicExceptions are not supposed to be caught.

…tener` raised by `StoreFactory`"

This reverts commit 0acd403.
@nicolas-grekas nicolas-grekas changed the title Fix LockStoreSchemaListener not working properly with iterable objects [DoctrineBridge] Fix LockStoreSchemaListener not working properly with iterable objects Apr 11, 2024
@nicolas-grekas
Copy link
Member

/cc @alexandre-daubois FYI

@alexandre-daubois
Copy link
Member

alexandre-daubois commented Apr 11, 2024

Indeed my solution doesn't work as expected. I don't think that reverting the PR is the best solution, because it would fix a bug but reintroduce one in the codebase.

I'm on my phone right now but I can have a look at it tomorrow to find/have a look for a proper solution, if you need help 🙂

@barton-webwings
Copy link
Contributor Author

I think there could be a better solution to the original issue #50761.

Personally, I would take a similar path to Monolog's NullHandler or Mailer's NullTransport and introduce a NullStore and a corresponding case to the StoreFactory. The DSN could look something like LOCK_STORE=null://.

This way we would avoid the InvalidArgumentException, which I agree is a legitimate exception, but preserve the option to effectively disable the Lock component.

@alexandre-daubois
Copy link
Member

Seems to be a great solution indeed, I like it!

@barton-webwings
Copy link
Contributor Author

barton-webwings commented Apr 12, 2024

I pushed a draft of my proposed solution into this PR, hopefully I didn't miss anything.

Since the StoreFactory already has cases which are not strictly a dsn, I went with a simple null, which would theoretically work with existing cases of LOCK_STORE=null.

Copy link
Member

@alexandre-daubois alexandre-daubois left a comment

Choose a reason for hiding this comment

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

Seems like a clean solution like this 😊

@nicolas-grekas
Copy link
Member

So, that's a new feature now, isn't it?

@Toflar
Copy link
Contributor

Toflar commented Apr 25, 2024

Not really a new feature. The current implementation is broken. It will not add the required schema as described in #54406. Just faced the same issue and this PR fixes it :)

@MatTheCat
Copy link
Contributor

MatTheCat commented May 4, 2024

The NullStore is a new feature.

#50761 revert is a fix.

*
* @author Pavel Bartoň <[email protected]>
*/
class NullStore implements BlockingSharedLockStoreInterface
Copy link
Member

Choose a reason for hiding this comment

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

Introducing this class (as well as the changes to the StoreFactory) must be moved into a separate PR targeting the 7.2 branch. That's a new feature.

@@ -40,20 +39,4 @@ public function testPostGenerateSchemaLockPdo()
$subscriber = new LockStoreSchemaListener([$lockStore]);
$subscriber->postGenerateSchema($event);
}

public function testPostGenerateSchemaWithInvalidLockStore()
Copy link
Member

Choose a reason for hiding this comment

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

this test should be kept as fixing the issue #50761 tried to fix is legitimate

}

$store->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
} catch (InvalidArgumentException) {
Copy link
Member

Choose a reason for hiding this comment

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

we still need catch the exception to not reintroduce the bug that #50761 tried to fix

@MatTheCat
Copy link
Contributor

@xabbuh there was in fact no bug prior to #50761: it is normal an exception is thrown when giving the StoreFactory an invalid DSN, and it is outlined by the fact said exception extends LogicException, which is not supposed to be caught.

@uwej711
Copy link
Contributor

uwej711 commented Aug 7, 2024

OK, so where do we go from here? Keep the current bug in 6.4, revert the commit that causes the bug and having the issue it tried to fix again or something else?

@xabbuh
Copy link
Member

xabbuh commented Aug 8, 2024

I would be okay with both solutions. Either reverting #50671 or switching to foreach). But the new null schema cannot be merged into 6.4 and must be moved into a PR targeting 7.2.

@barton-webwings
Copy link
Contributor Author

I am closing this PR, as it is superseded by #57944.
I am actually only interested in the bugfix part of this issue, so we can remove the workaround after update.
If someone wants to make a PR for the new feature introduced, feel free.

nicolas-grekas added a commit that referenced this pull request Aug 13, 2024
…Cat)

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

Discussion
----------

[DoctrineBridge] Fix the `LockStoreSchemaListener`

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #54406
| License       | MIT

#54407 got sidetracked ~and `@barton`-webwings seems no longer active on GitHub~ so this PR takes over.

Commits
-------

db070a1 [DoctrineBridge] Fix the `LockStoreSchemaListener`
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.

8 participants