Problem/Motivation

The issue was covered by #3020112: [Regression] API change in jsonapi module., but once that was resolved, it uncovered this particular one.

The issue is once jsonapi_extras is installed unless you explicitly SAVE the resource type fields are not shown through the API.

In short the default behavior has regressed and any time that a NullResourceType is used, the particular resource in the API will not have fields present in the payload.

This is caused by code from jsonapi_extras (the early return):

  /**
   * ...
   */
  protected function overrideFieldMapping(JsonapiResourceConfig $resource_config) {
    if ($resource_config instanceof NullJsonapiResourceConfig) {
      return [];
    }
    // ...
  }

And how NULL configs handle fields...

Proposed resolution

Any direction on how to resolve this, and feedback on whether the current patch direction is ok-ish.

Except the patch, there is a semi-work-around - go in the UI and re-save all entity configs manually and export that as configurations, so we are not using the NULL configs anywhere. At that point everything will be marked as overwritten and maintenance efforts will greatly increase. This is first not a scalable option and it is not a valid one, as we can not expose web forms and similar dynamic things through JSON:API anymore.

I will propose to extend the NULL type with a valid original ID (even if it's NULL) so we can fetch field mappings for it if needed.

This is jsonapi_extras issue due to the fact it's resolved once jsonapi_extras is disabled as seein in #5.

Remaining tasks

  1. Direction approval.
  2. Resolve the API write issue in tests and/or code (TBD).
  3. Patch (we have API-read scenario working now)
  4. RTBC
  5. Commit

User interface changes

None.

API changes

None expected...

Data model changes

None.

Release notes snippet

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ndobromirov created an issue. See original summary.

ndobromirov’s picture

Issue summary: View changes
ndobromirov’s picture

Issue summary: View changes
ndobromirov’s picture

What was the reasoning behind NULL configs?
With all the caches involved, in the process now is the speed-up from NULL configs still meaningful?
Why not just instantiate fully valid resource configurations based on system state instead of NULL instances and just have a flag that they are default.
Add a DefaultResourceConfig(entity, bundle), so upon creation, this will be handled transparently from:

  protected function getResourceConfig($resource_config_id) {
    try {
      $resource_configs = $this->getResourceConfigs();
      return isset($resource_configs[$resource_config_id]) ?
        $resource_configs[$resource_config_id] :
        new NullJsonapiResourceConfig([], '');
    }
    catch (PluginException $e) {
      return new NullJsonapiResourceConfig([], '');
    }
  }

Just throwing ideas... :(

ndobromirov’s picture

Disabling the jsonapi_extras is resolving the issue, so it's not jsonapi related.

ndobromirov’s picture

Status: Active » Needs review
FileSize
1.55 KB

Here is an atempt at a fix...

Status: Needs review » Needs work

The last submitted patch, 6: 3020237-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rhristov’s picture

Applying a new patch that is fixing the issue: it fallbacks to the default JSONAPI resource type and field item normalizer if the configuration is not overridden.

rhristov’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: regression_jsonapi-3020237-8.patch, failed testing. View results

ndobromirov’s picture

Status: Needs work » Needs review
FileSize
1.73 KB

Handle the exception case as well in the same manner...

Status: Needs review » Needs work

The last submitted patch, 11: 3020237-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ndobromirov’s picture

I am sure that at least some of the tests are now broken and this is jsonapi 2.x related somehow. Terms tid is now exposed as drupal_internal__tid.

ndobromirov’s picture

Issue tags: +API-First Initiative
ndobromirov’s picture

Status: Needs work » Needs review
FileSize
2.77 KB
1.04 KB

Updating tests should resolve one of the failures as it seems like a change in the structure there.

Status: Needs review » Needs work

The last submitted patch, 15: 3020237-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ndobromirov’s picture

The only failing test is write through the api.
As this is not a use case for us, we can use the patch as is.


Any support to make this green will be appreciated as I am not 100% sure how to test the writes manually :)!
vtcore’s picture

Just updated jsonapi to from 2.0-rc2 to 2.0-rc3 and exactly the same thing happened. For not overwritten resources the response is missing the attributes property.
Another thing is that the nid and vid properties are now drupal_internal__nid and drupal_internal__vid while in the overwrites UI of JSON:API Extras they are still named nid and vid.

ndobromirov’s picture

Title: [Regression] Broken with latest jsonapi 2.x-dev » [Regression] Broken with latest jsonapi 2.0-rc3
daniel.nitsche’s picture

I haven't had time to test this thoroughly, but the patch in #15 seems to bring back attributes and relationships where they were previously missing.

@vtcore -- should a separate issue be logged for the nid/vid issue?

ndobromirov’s picture

cspitzlay’s picture

My 2 cents:

I had similar issues: supposedly unkown filter fields (and missing fields in the output when not filtering).
I tried #15 and it solved the issue in my test cases.

ndobromirov’s picture

Issue summary: View changes

Updated issue summary with latest findings...

e0ipso’s picture

Status: Needs work » Needs review
FileSize
10.68 KB

  • e0ipso authored 29cb1c0 on 8.x-3.x
    Issue #3020237 by ndobromirov, rhristov, e0ipso, vtcore, daniel.nitsche...
e0ipso’s picture

Status: Needs review » Fixed
e0ipso’s picture

Good call @Wim Leers. Thanks for this!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

audriusb’s picture

I am still having an issue in v3.3. file field is always empty but it comes back populated when I disable jsonapi_extras. trying with jsonapi 2.1