Skip to content

[Scheduler] Trying to access the DB in a ScheduleProvider breaks migrations / tests / ... #51112

Closed
@mrossard

Description

@mrossard

Symfony version(s) affected

6.3

Description

If your ScheduleProvider tries to access the database, you can't run tests that recreate the DB or run your migrations from scratch anymore, as the getSchedule() gets called first and fails as it tries to get its configuration from the DB.

How to reproduce

Create a ScheduleProvider that does something similar to this:

public function getSchedule(): Schedule
    {
        $frequency = $this->parameterRepository->findOneBy([
            'key' => Parameter::REMINDER_FREQUENCY,
        ]);

        $frequency = $frequency->getValue();

        return (new Schedule())->add(
            RecurringMessage::every(frequency: $frequency,
                                    message  : new SomeMessage(),
                                    from     : $this->now())
        );
    }

Then just try to run bin/console doctrine:migrations:migrate on an empty DB. You'll get SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "parameter" does not exist as it tries to run getSchedule() first. Same things with my behat tests that recreate the DB, everything just fails.

Possible Solution

No clue right now. I may have missed something, as this is still pretty new?

Additional Context

My current transport for messenger is doctrine://default, that might be linked?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions