-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
Introduce sanity checks for IDs and fix overriding its type #1190
Conversation
} | ||
|
||
// \MongoId::isValid($idValue) was introduced in 1.5.0 so it's no good | ||
if ($class->generatorType === ClassMetadata::GENERATOR_TYPE_AUTO && $idValue !== null && ! preg_match('/^[0-9a-f]{24}$/', $idValue)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, this could happen with any generator strategy, including custom. It probably would be best if the generator itself could handle this check, including on whether to ignore it, throw an exception or quietly change the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partially I agree but since AUTO strategy is the default one its misuse is the most problematic (see #819 or tests I needed to fix in this PR like this one), I think we can safely assume that if somebody is changing strategy he is clever enough to pass correct id (or will have his own checks in the type).
To be honest, I don't know why we have the generatorOptions type at all. In the end, it does exactly the same as the field mapping but it just introduces complexity and mistakes along the way. I'm not sure about BC here, but IMO the best option would be to drop generatorOptions.type, always use type from the field mapping and setting it to Either way we do this, we need to write some documentation about this feature. |
Maybe trigger deprecation?
What is the point of such generator?
I'll create a ticket for this later |
The use case is a bit special: we needed predictable identifiers to trigger upserts but wanted to keep |
@alcaeus I've commited a change we discussed on IRC :) |
Introduce sanity checks for IDs and fix overriding its type
Fixes #857 (and by the way fixes #1178), closes #1183 and closes #819.