Skip to content

Conversation

@whataboutpereira
Copy link

Fix for issue #11794.

Currently the values of enumType in DiscriminatorColumn are ignored which results in an error when generating a migration:

Doctrine\DBAL\Platforms\MySQL80Platform requires the values of a ENUM column to be specified.

Fixed by populating values from the enum and also prevent invalid entries in DiscriminatorMap.

@whataboutpereira
Copy link
Author

What's the correct way to turn off tests for DBAL versions not supporting enumType?

@greg0ire
Copy link
Member

You could mark the test as skipped unless Doctrine\DBAL\Types\EnumType exists.

@whataboutpereira
Copy link
Author

Let's try this now.

@whataboutpereira whataboutpereira force-pushed the fix-enum-discriminator-column branch from 9ad4a23 to fa84570 Compare August 4, 2025 15:15
@whataboutpereira
Copy link
Author

MySQL also required. :)

@whataboutpereira whataboutpereira force-pushed the fix-enum-discriminator-column branch from fa84570 to 15bb988 Compare August 4, 2025 15:24
@whataboutpereira
Copy link
Author

Sorry, that was depressing. Last attempt for now.

@greg0ire greg0ire changed the base branch from 3.5.x to 3.6.x August 4, 2025 16:12
@greg0ire
Copy link
Member

greg0ire commented Aug 4, 2025

Retargeting to 3.6.x since this is a new feature.

}

if (! $this->getTestEntityManager()->getConnection()->getDatabasePlatform() instanceof AbstractMySQLPlatform) {
self::markTestSkipped('Test valid for MySQL/MariaDB only.');
Copy link
Member

Choose a reason for hiding this comment

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

Why shouldn't we run this test on other DBMS?

Copy link
Author

Choose a reason for hiding this comment

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

Tests were failing on SQLite. I'm not sure which other feature detection we should use to skip.

Copy link
Member

Choose a reason for hiding this comment

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

Why were they failing though?

Copy link
Author

Choose a reason for hiding this comment

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

The more I look at it it the more confused I get. :) Now I'm thinking Types::ENUM doesn't need to be involved at all when setting the values in ClassMetadata, because you should still get the values from the enum class even if not using type enum in the database. But it's 2AM, will test tomorrow.

@whataboutpereira whataboutpereira force-pushed the fix-enum-discriminator-column branch 2 times, most recently from f4617f5 to 689a5eb Compare August 5, 2025 07:16
@whataboutpereira
Copy link
Author

whataboutpereira commented Aug 5, 2025

That's odd. When I run sqlite test locally with dbal 3.10, the test is marked skipped.

@whataboutpereira
Copy link
Author

Things got a bit clearer. It seems I was mislead by the title "Implement an EnumType for MySQL/MariaDB", where in fact it works for all databases, but just maps the value to string. So Types::ENUM should always be used to populate values.

@whataboutpereira whataboutpereira force-pushed the fix-enum-discriminator-column branch from 76dcaee to b84e46a Compare August 8, 2025 21:17
@greg0ire
Copy link
Member

Can you please squash your commits together and give the remaining commit a good message?

Check DiscriminatorMap keys match enum cases.
Test values are populated from enum cases and mismatched values throw an exception.
Fixes doctrine#11794
@whataboutpereira whataboutpereira force-pushed the fix-enum-discriminator-column branch from b84e46a to 6da5cc4 Compare August 19, 2025 11:50
@whataboutpereira
Copy link
Author

Can you please squash your commits together and give the remaining commit a good message?

Thanks, done now. Hopefully correctly. :)

@greg0ire greg0ire modified the milestone: 3.6.0 Aug 26, 2025
);
}

$values = $this->discriminatorColumn->options['values'] ?? null;
Copy link
Author

Choose a reason for hiding this comment

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

I'm now thinking we should wrap these checks in if ($this->discriminatorColumn?->enumType !== null), otherwise DiscriminatorColumn without enumType, but with options: ['values' => ['...']] will fail. Though values probably shouldn't be used without.

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.

3 participants