Closed (fixed)
Project:
Drupal core
Version:
8.4.x-dev
Component:
rest.module
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
31 May 2017 at 13:04 UTC
Updated:
6 Feb 2018 at 14:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersComment #3
wim leersComment #4
wim leersAdded to #2852860 in #2852860-36: REST: top priorities for Drupal 8.4.x.
Comment #6
wim leersEvery single
hal+jsonformat test is failing. Probably due to_links.Also, the others that fail are:
CommentEntityTestLabelEntityTestShortcutTermUserAnybody interested in pushing this further?
Comment #7
dawehnerI might give it a try later ..., let's see :(
Comment #8
wim leersInteresting that the number of failures is different on 8.3.x vs 8.4.x!
Comment #9
dawehnerI tried to do some research why it fails ... and well, it turns out the output format of an entity with an entity reference is different to its input for hal_json. Just compare
the entity_id entry with the bits produced in
\Drupal\Tests\hal\Functional\EntityResource\Comment\CommentHalJsonTestBase::getExpectedNormalizedEntityIt feels like
\Drupal\Tests\hal\Functional\EntityResource\Comment\CommentHalJsonTestBase::getNormalizedPostEntityis implemented in the wrong way, as it needs some transformation applied, OR the new testcode should call out to getExpectedNormalizedEntity instead.Comment #10
wim leersThis fixes a whole bunch of the failures, which were happening because there is a discrepancy between what the denormalizers accept vs the normalizers generate: we accept
['type' => 'blah']because Field API magic automatically maps this to['type' => ['value' => 'blah']]for single-property field types. Some of the request bodies were using that "feature". Simply changing the request body to their "fully expressed" equivalents solves many of the failures (because it means we can actually check that the request body is a subset of the response body).Comment #11
wim leersSimilar, yet different:
UserResourceTestBase::getNormalizedPostEntity()was using a randomly generated name. This meant that every call to that method returned a different name. Which makes testing impossible. It's also the only entity REST test to do this. So, shifting to a hardcoded name, just like all other tests, is enough.Comment #12
wim leersThe
Termtests are failing in a different place: loading the entity from storage and then normalizing it yields a different result than the normalization we get from decoding the serialization in the response body.Why?
Turns out that
causes
$term->fields->parentto be initialized to have this value:'target_id' => 0. So that's also what we see in the PATCH/POST response body:['parent' => [['target_id' => 0]].But if we load a stored term entity,
$term->fields->parentdoes not exist at all, because there's no value set for it. Hence it's normalized to['parent' => []].Similar story for
$term->description.A potential work-around is for us to explicitly specify a
target_idand adescriptionin our PATCH/POST request body. But turns out that only solves thedescriptioncase — apparently specifyingtarget_id = 0specifically still causes a['parent' => []]normalization! Actually, even settingtarget_id = 1causes this. Probably because is configured to use custom storage:But then I realized… we already have an issue for this: #2543726: Make $term->parent behave like any other entity reference field, to fix REST and Migrate support and de-customize its Views integration.
Comment #15
wim leersThe remaining problems with
Userare field-access related. The new assertions being added by this patch contain a simple but severe bug:This is normalizing the given entity. Content entity normalization checks field access. Field access uses the current user by default. In this environment, there isn't a current user, so it falls back to the anonymous user. That explains why
User*AnonTestare passing, but not basic_auth/cookie tests!So, we need this to normalize with the same user account as our actual tests. That's all :)
Comment #17
wim leers#12 should bring it down to 10 failures. #15 to 4.
#8:
The reason is simple:
\Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDateonlyTestand\Drupal\Tests\datetime\Functional\EntityResource\EntityTest\EntityTestDatetimeTestonly exist in 8.4.x! And since #10 fixed the failures forEntityTest, those failures were also fixed.That now only leaves
CommentHalJson*TestandItemHalJson*Test.Comment #19
wim leersThe failing
CommentHalJson*Test: for some reason theentity_idfield is missing in POST response bodies (so, @dawehner, thank you very much for #9, but AFAICT that's not what is happening :O). I tried reproducing this manually: POSTing a HAL+JSON comment, and stepping through the normalization process to observe whyentity_idwas missing… only to observe that it's actually generated just fine :/ I have no explanation for this. Other than: WTF?! — at least for now :)Similarly, the failing
ItemHalJson*Testthe problem is similar: thefidfield is missing in POST response bodies. I haven't done any step-by-step debugging there yet.If somebody else could push this one over the finish line, that'd be wonderful!
Comment #20
wim leersThis is blocking #2300677: JSON:API POST/PATCH support for fully validatable config entities, which is major, hence this is major too.
Comment #21
dawehnerWell, if you have a look at
\Drupal\hal\Normalizer\EntityReferenceItemNormalizer::normalizeyou'll not see the entity_id to be included, also see\Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait::applyHalFieldNormalization:Comment #22
wim leersComment #23
wim leers#21 Turns out that's it. I wonder how the hell I managed to observe something else in my manual testing in #19 then… I think I might've confused
entity_idandid? (That is quite confusing inCommententities.)With that confirmed, let's work on the fix. The root cause of this problem is:
Using
assertArraySubset()is simply a bad assumption: this assumption only holds for the simplest possible normalization, i.e. the default normalization that Drupal uses. But it breaks down for HAL+JSON, as well as for e.g. JSON API.Then a better way to assert that the sent values are indeed present is by iterating over all fields in the normalization that's being POSTed and then comparing that with the actually stored values.
This reroll brings us to just 3 failures. The remaining 3 failures are in
UserHal*Test::testPatch(). Investigating…Comment #24
wim leersThose 3 remaining failures had the same root cause as #15, I just only thought of fixing it for
testPost()in #15. This then fixes it fortestPatch()too.This is ready for final review.
Comment #26
tedbowThis looks good to me.
Nice work @Wim Leers and @dawehner
Comment #27
dawehnerNice!
Comment #28
wim leersWhew, so glad to have this be RTBC! It'll be great to finally start pushing #2300677: JSON:API POST/PATCH support for fully validatable config entities forward again, after @dawehner's incredible effort to get that going again!
Comment #29
catch"and that the response body the". Is it missing 'contains'?
Otherwise looks good though.
Comment #30
wim leersIndeed that word is missing. It's present for the
PATCHtest coverage. Fixed :)Comment #31
catchCommitted/pushed to 8.4.x, thanks!
Comment #33
wim leersThis unblocked #2300677: JSON:API POST/PATCH support for fully validatable config entities, yay!
Comment #35
wim leersAnd now we're removing the temporary work-around that this introduced: #2942522: Follow-up for #2543726: remove work-around in POST test coverage for bug in Term entity type that has been fixed — hurray!