Problem/Motivation
@penyaskito found this on #2976334: Allow Custom blocks to be set as non-reusable adding access restriction based on where it was used.
This made one of my upgrade tests fail:
1) Drupal\Tests\lingotek\Functional\Update\LingotekTargetStatusFormatterUpdate8209Test::testUpgrade
Schema key views.view.block_content:display.default.display_options.filters.reusable.group failed with: variable type is string but applied schema class is Drupal\Core\TypedData\Plugin\DataType\IntegerDataFound out the culprit here. The attached patch fixed it. Maybe we are missing some coverage in the upgrade tests?
I am not sure why LingotekTargetStatusFormatterUpdate8209Test
failed but \Drupal\Tests\block_content\Functional\Update\BlockContentReusableUpdateTest
did not.
I don't think affects the functionality the update still works so that is why I am creating a follow up.
Proposed resolution
- Change to an int
- Figure out why our update test didn't catch this. Presumably all update test would have broken in the same way.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#15 | 2988435-15-with-int.patch | 1.03 KB | effulgentsia |
#15 | 2988435-15-with-int-like-string.patch | 429 bytes | effulgentsia |
#13 | 2988435-13-should-fail.patch | 1.03 KB | effulgentsia |
#8 | 2988435-should-fail.patch | 624 bytes | effulgentsia |
#6 | 2988435-fix-assert-same.patch | 5.48 KB | tedbow |
|
Comments
Comment #2
tedbowTest run!
Comment #4
tedbowThis is @penyaskito's patch. Crediting
Comment #5
effulgentsia CreditAttribution: effulgentsia at Acquia commentedRaising to Critical, since it's an upgrade path error.
Comment #6
tedbowOk here are couple patches
both modify core/drupalci.yml to only run "Drupal\Tests\block_content\Functional\Update\BlockContentReusableUpdateTest"
2988435-no_fix_equals_passes
assertEquals
to test that views actually do get updated now. I also show that withassertEquals
1 or '1' is the same and will pass2988435-fix-assert-same
Has the fix
Uses
assertSame
which will check typesBigger problem
I think 2988435-no_fix_equals_passes proves that what is committed now actually does save the filter and
BlockContentReusableUpdateTest
tests that filter is respected after the update.I think for Views the '1' or 1 will work the same.
But are update tests aren't actually throwing exceptions when we update config and don't get the schema exactly right.
I have created a locally update test that simply does
you can see here that I was trying different fixture files. None of the fixtures I tested from core throw the schema error but
drupal-8.lingotek.standard.pre8209.php.gz
did.I am not sure what the difference is.
We should probably open a general schema testing issue for this to prove it is the case.
Comment #7
effulgentsia CreditAttribution: effulgentsia at Acquia commentedI don't know. But another factor here is that
'1'
does not violate the config schema of integer, becausePrimitiveTypeConstraintValidator::validate()
merely does afilter_var($value, FILTER_VALIDATE_INT)
check, which passes for integer-like strings.So potentially this bug isn't Critical after-all, but still worth fixing and figuring out how to make the test coverage more robust.
Comment #8
effulgentsia CreditAttribution: effulgentsia at Acquia commentedThis should fail if our update tests are validating config schema.
Comment #9
effulgentsia CreditAttribution: effulgentsia at Acquia commentedBy the way, #2414951: Validate configuration schema before importing configuration would make it easier to test config for schema validity via the UI, but alas, we don't have that yet.
Comment #10
effulgentsia CreditAttribution: effulgentsia at Acquia commentedHm, yeah, I think #8 passing is a concern. I don't know yet if there's something specific to this issue that's causing it to pass (e.g., the
'1a'
is being converted to a1
at some point in the update process) or whether theassertConfigSchema()
inrunUpdates()
is failing to catch schema violations. If the latter, then a new issue makes sense. If the former, we should probably figure it out in this issue.Comment #11
penyaskitoI created
drupal-8.lingotek.standard.pre8209.php.gz
with 8.5.x. Maybe that's a thing.Comment #12
effulgentsia CreditAttribution: effulgentsia at Acquia commentedI think #11 is correct. I think what's likely happening is that the test is running some other post_update function after
block_content_post_update_add_views_reusable_filter()
, and that later running one is cleaning up any schema mismatch created by the former one. I suspect the culprit is theviews_post_update_filter_placeholder_text()
function added in #2917594: Add support for HTML5 placeholder in views exposed filters, since that's doing a$view->save()
without either usingConfigEntityUpdater
or invoking$view->trustData()
directly. Also, that issue was committed to 8.5.x, but not to 8.4.x, which would explain the difference between a test run starting from an 8.5 database vs. an 8.4 one.Comment #13
effulgentsia CreditAttribution: effulgentsia at Acquia commentedTesting #12's hypothesis.
Comment #15
effulgentsia CreditAttribution: effulgentsia at Acquia commentedGreat! Ok, let's try these now then.
Comment #16
tim.plunkettThat's the nice thing about ConfigEntityUpdater, you don't need to remember the magic of trustData() yourself.
Might be worth a follow-up to go back through old update functions to switch them to that, just to establish the patten for those seeking to mimic an update function.
Comment #18
effulgentsia CreditAttribution: effulgentsia at Acquia commentedAdding reviewer credit.
Comment #21
effulgentsia CreditAttribution: effulgentsia at Acquia commentedI pushed @penyaskito's original patch (#4) to 8.7.x and 8.6.x.
I'll open a new issue to discuss changing already released post_update functions, like the one in #15.
Comment #22
effulgentsia CreditAttribution: effulgentsia at Acquia commentedHere's that new issue: #2989256: Old post_update functions that ->save() config entities without calling ->trustData() first mask errors in other post_update functions.