We have 2 content types, Page and Blogpost. In one of them, the path attribute shows, including the alias. In the other one no path.
Should be always visible? Any clue how can I debug this?
I tried disabling JSON API Extras, same result
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | image (3).png | 236.49 KB | phonoman |
| #5 | url_alias.png | 179.06 KB | corbacho |
| jsonapi.png | 431.07 KB | corbacho |
Comments
Comment #2
wim leersThis reminds me of #3012019: Include the path / url alias. Over there, the root cause was #3012019-11: Include the path / url alias:
Perhaps that's also what's going on with your site?
Comment #3
wim leersIronically, that was reported by a former colleague of yours :D
Comment #4
wim leersYour screenshot got me thinking. I did some searching. It seems #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) would give you the behavior you were expecting.
Comment #5
corbacho commentedThanks Wim!, I saw the #3012019 issue before. This is a different project, and I unfortunately never met before Michael Moritz, former wunder colleague.
In that issue Gabe's response "I think you mean that you're not seeing the alias in the response at all? That doesn't seem right." , then made me think that JSON API should offer a "path" object by default, at least in node entities?
A URL alias would be nice, and I think we will use #2511968 patch, but still doesn't fix the original root issue, that is the lack of "path" object
The content is exposed through '/jsonapi', (default language English), so I wouldn't expect translations-related issue.
And I attach another screenshot, where both content pages and blog posts have automatic alias by default.
Also, if I force a path for the a specific node (not automatic alias), it won't show up in the json api response
I will try to debug it tomorrow, and post more info. But if you have any clue, it's appreciated :)
Comment #6
wim leersI quoted the clue in #2, but I realize it’s still pretty vague. So let’s make it more concrete.
I strongly suspect that your problem is that the entity with the “missing” path attribute actually has a path alias with a langcode that is different from the entity’s langcode. I bet that making it match will result in it showing up!
Comment #7
wim leersAlso: please update to RC2!
Comment #8
phonoman commentedUpdating the module didn't bring any changes on this.
Comment #9
wim leersI did not expect it to, but thanks for confirming! 🙏
Comment #10
phonoman commentedOkay, I tried reverse engineering the content types and re-creating the issue, where's what I got:
entity_clonemodule I duplicated one of the faulty content types => it didn't show the path same way the original content type didn't.Then I went and deleted every single field from the duplicated content type (to check if another field might be causing issues) 1 by 1. After having no fields left in the entity there was still no path property to be seen.
During the last testing I remembered that on updating Drupal core (8.5 => 8.6) there were configurations (after drush updb) that were lost (
drush updb+ instantlydrush cimafter updating core) although there should've been an export after updating the database.But I'm not sure if it has anything to do with this issue, though, as some of the old content types also display path fine.
Also, could it really have something to do with the database if creating an identical content type which reuses the exact same fields (that are used by the broken content type) work fine?
Comment #11
Nick Lewis commentedI've had similar issues, but I don't think it is actually jsonapi's fault. Seems to be a core bug. I've noticed that if I inspect the load tab in devel $node->path is missing there as well. Steps to reproduce are pretty simple:
1. New d8 standard install.
2. Create an article and page with alias.
Path will show in devel tab.
3. Enabled content translation and enable it for those content types.
Path will disappear in devel tab. Seems to be a permanent buggy state. Simply disabling translation will have no effect.
I wasn't able to get rid of this bug til I did hard uninstalls of all translations modules, deleted all aliases, and did a hard uninstalled the path module itself (do not remember that being an easy process).
Comment #12
wim leersCould you both apply the latest patch at #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) and report back?
Comment #13
phonoman commentedNick, you're pretty spot on with your thought.
We found out that this issue occurred to only few old content types (new/healthy copies of content types always had the path attribute). David[corbacho] took notice of your 'base field override' suggestion, Wim, and run into https://drupal.stackexchange.com/questions/271598/how-to-remove-base-field-overrides where he found
drush config:delete core.base_field_override.node.[Problematic_ContentType].pathwhich then deleted the config for[Problematic_ContentType].path.ymlfile and path attribute showed up once again after a cache clear.Apparently there were some of "empty looking" overrides left in the configs. I'm not sure how those configs got created one/two years ago from exporting production content.. but they apparently did.
Added a screenshot where we see the faulty config that doesn't even have any callbacks. Either way - removing the faulty config (
Problematic_ContentType.path.yml) did the trick and we're able to access our beloved url alias once again! :)Comment #14
wim leersI'm glad that you've been able to confirm it had the same root cause as #3012019: Include the path / url alias, but you both explained it much more clearly!
Also, #2511968: Path field should fall back to language neutral aliases (also makes this happen for the form widget!) landed! I suspect (I'm not certain since I haven't gone through all the steps listed to reproduce it, which I'd need to do to be able to step through it with a debugger to be 100% certain) that that will actually also prevent this problem.
Comment #15
Nick Lewis commented#3012019 was definitely the same issue (it was fixed on fresh install!). I'll give #2511968 a test tomorrow... The database tables have actually behaved really well in my tests... I think Phonoman hit on the head... it's not a database problem... It's a config issue. This is why my hard reinstalls fixed it. This is maybe why #3012019 was fixed on fresh install? One thing I do know is that I was able to fix it by creating a new custom computed field on an existing site. The same module fails just as path would on a new site.
Comment #17
coufu commented#13 was lifesaver. Thank you Phonoman
Comment #18
alex.bukach commentedDeleting the
core.base_field_override.*.ymlconfig make sense only if the field is not actually overridden. If anyone faces the missing path issue and needs to keep the field properties overridden, please try the patch at https://www.drupal.org/project/drupal/issues/3274419 and let me know whether it helps.