Needs work
Project:
Drupal core
Version:
main
Component:
plugin system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Apr 2013 at 14:51 UTC
Updated:
4 Feb 2023 at 23:57 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
claudiu.cristeaYes, we need to be consistent across PHP <=> YAML <=> Annotation. While NULL is supported by PHP and YAML we need it also in annotations.
BTW, what is the reason for not supporting NULLs?
And this is not a "feature request", it's a bug.
Comment #2
claudiu.cristeaI just tested NULL values in ImageItem plugin and it work. Looked also in Doctrine and they seems to handle NULLs.
I would close this as "works as designed". What you think @Xano?
Comment #3
xanoMy initial confusion came from the conversion from annotation objects to arrays, which is a different way of accessing data, and where type hinting through code comments gets lost. The fact that any annotation property that ends up being NULL is discarded by the parser and does not end up in the final definitions array was extra confusing, especially because it's something that was explicitly defined beforehand and does end up in the array structure once there is a value.
However, both things are indeed by design, and are a part of Doctrine\Annotations and not Drupal anyway, so this issue may well be a won't fix. However, I'd still like to hear opinions from other Drupal developers.
Comment #4
xanoBump.
Comment #5
dawehnerI cannot imagine that this is a real problem, if you need something like that use '' or FALSE. Php is not strictly typed anyway.
As a process I would recommend to support it in Doctrine/Annotations and if they don't accept it, just live with it.
Comment #6
xanoThis hasn't got anything to do with Doctrine, but with Drupal filtering out NULL values.
Strict typing isn't the issue. We can use FALSE, but that may be misleading. The real question is why NULL values are filtered out in the first place. There is no reason, but it makes using optional definition values more verbose.
Comment #8
xanoSo there is one key we can ditch...
Comment #10
xanoComment #12
tim.plunkettIIRC, we filtered that out in order to keep the EntityType array cleaner, since some keys were only for each kind of entity type, before we had the ConfigEntity/ContentEntity split.
See #1967294: Add a dedicated @EntityType annotation.
So, I think we can remove that filtering, but we should add test coverage to prove it is possible.
Comment #13
xanoHere's a test. Since there was no unit test for the class at all, I took the liberty of also adding coverage for the class's other methods.
Comment #14
tim.plunkettJust skimming the test, it doesn't seem to cover the new change. It should be more clear with a NULL value, as well as ensuring 'definition' isn't retained.
Comment #15
xanoThanks for pointing out! That is a stupid mistake indeed.
I added a check for
NULLvalues, and random annotation properties, as well as a check for the non-existence of thedefinitionproperty itself.Comment #16
xanoThis is going well...
I forgot to rebase before rolling the patch. Here is a significantly smaller patch made after the rebase.
Comment #20
tim.plunkettThis is considered a risky test since it has no assertions.
Comment #21
xanoDo you have an alternative way of testing in mind? The other testing methods provide actual assertions, so there is code coverage for everything. Shall I remove this method and add
@covers ::__constructto the other test methods?Comment #22
claudiu.cristeaWhy a test only for the constructor while an object is constructed in
::setUp()meaning is tested in each test. I think adding the annotation to the first test it's enough.Comment #23
xanoLet's make sure we have annotations for all methods then.
Comment #24
claudiu.cristeaAdded IS and Beta Evaluation.
Comment #29
claudiu.cristeaRerolled, removed @file from test, moved to 8.2.x.
Comment #38
quietone commentedRerolling the patch.
Comment #40
ridhimaabrol24 commentedFixing failed tests.
Comment #41
quietone commented@ridhimaabrol24, thank you for working on this to fix the failing test. I see that the change is adding the 'minimum_version' property to the migrate source plugins. Is that what we want to do?
I think this needs work to investigate the 'minimum_version' property of migrate source plugins.
Edit: s/field/source
Comment #42
quietone commentedDoing some digging.
I'm not familiar with the minimum_version property of migrate source plugins so I grepped:
That's a bit noisy with returns related to the Database system and not a plugin property. The line of note is
core/modules/migrate/src/Annotation/MigrateSource.php: public $minimum_version;I know that checkRequirements does a schema version check so I looked at DrupalSqlBase, grepping for 'minimum_schema_version'.
So MigrateSource defines $minimum_version, as mixed, which is not used anywhere in migrate and DrupalSqlBase uses $minimum_schema_version. The docs for $minimum_version say that migrate drupal source plugins expect minimum_version to be an integer representing the minimum installed database schema for the module. But then DrupalSqlBase tests with $minimum_schema_version, a value that is not defined or set anywhere.
That suggest to me that DrupalSqlBase should be testing with $minimum_version not $minimum_schema_version. For me, that is a bug and DrupalSQlBase should use $minimum_version.
Now, as regarding this issue is it OK to set $minimum_version to NULL on all source plugins? The short answer it yes in migrate. The annotation set the type as mixed. So that is fine. Now, for DRupalSqlBase. It is currently isn't using $minimum_schema so that won't matter. And once DrupalSqlBase is fixed it will be using $minimum_version and an isset is done before doing any comparison with it. Again, that is fine.
Comment #43
quietone commentedFixing coding standards errors.
Comment #44
quietone commentedCreated a follow up in migration for the problem described in #42, #3151732: DrupalSqlBase::checkRequirements should test version with $minimum_version.
Comment #45
tanubansal commentedTested via adding patch #43 : Remove NULL filtering from \Drupal\Component\Annotation\Plugin to allow NULL in annotation default values
Changes are visible and this can be moved to RTBC
Comment #46
quietone commented@tanubansal, thank you for interest in moving this patch along and contributing to Drupal. Please read the issue to see if screenshots are needed before adding them. Screenshots are typically only for issues that alter the UI.
As I mentioned in #3159849: Add missing tests of filepath to FileTest Comment #5 there is a wealth of information on Drupal about contributing.
Comment #47
tanubansal commented@quietone : thanks ... i will take care in future
Comment #48
quietone commented@tanubansal, thank you! If I can be of any help I can be in #migration on Drupal Slack.
Comment #50
quietone commentedNeeded a reroll
Comment #55
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Didn't see a test patch so running locally
d6/FieldDiscoveryTest
d7/FieldDiscoveryTest
PluginTest actually passes. (not sure an issue)
Reviewing the fix
Appears to be doing what the IS states.
Looks good to me.
Comment #56
tim.plunkettPluginTest failing without the fix is a blocker IMO. The other two are test tweaks needed to adapt to this change, but the unit test for this code should absolutely cover this.