Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork331
Change drupal_internal__* to internal_* in JSON:API responses#987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:4.x
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
symbioquine commentedAug 4, 2025
Haven't looked at the code, just thinking about the idea... On one hand this seems like a positive change in that it allows those ids to be documented as part of the farmOS reference implementation (of the farmOS datamodel/api) without weird coupling/artifacts to/of Drupal. On the other hand, I wonder if we should/can avoid and discourage use of those ids in favor of the UUIDs for programmatic usage and some sort of more meaningful reference (like the 1.x permalinks I guess) value for human usage? Put another way, there's two questions;
|
mstenta commentedAug 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I pushed a There are two |
mstenta commentedAug 4, 2025
@symbioquine Good questions...
The If a third-party application wanted to leverage data stored in revisions it would need to use this internal ID, I believe.
I'm not sure if I understand this question, but I can think of one case were internal IDs are better to use than UUIDs. Configuration entities (eg: a user's role) have non-numeric internal IDs (like These two Drupal core issues explain why the https://www.drupal.org/project/jsonapi/issues/3034701#comment-12981809 |
symbioquine commentedAug 4, 2025
The "we" I was referring to is anybody calling the API I guess. I wasn't so much thinking of the revisions case with
Another example is anybody generating QR codes will tend to prefer the shorter numeric values for generating URLs since those will be shorter and thus result in smaller easier to scan QR codes. Similarly, anywhere somebody might need to type in a URL or hand-validate one, the numeric code will be more user-friendly. (Hopefully this is rare) Another example is tests which insert/modify data and then access it via the API are probably more readable with the numeric ids vs the UUIDs. Although in this case having the "drupal_internal" prefix isn't terrible, it suggests that we shouldn't be marking these ids as neither "internal" or "Drupal specific" if that's what we're actually testing against. Summing that up;
|
mstenta commentedAug 4, 2025
Makes sense - these are all great questions - perhaps worthy of a broader forum discussion on the topic. I worry about them getting lost in this PR, which only pertains to the JSON:API aliases given to the internal IDs, currently: I forgot to highlight this in my original description, but the reason I'm proposing this small change right now is because it would technically be a "breaking change" so it's something worth considering for 4.x in the very near term. |
gbathree commentedAug 5, 2025
My two cents here... I think the current internal IDs are fine. They are helpful in case an external user wants to use them to query the API via a URL or similar... generally however I agree that they are inferior most of the time compared to the actual UUIDs which should always be present. In general, IMO I would keep them. Re. removing the |
mstenta commentedAug 13, 2025
@paul121 suggested a clever workaround on the dev call today... In Drupal 11.2 (#980) JSON:API now supports adding metadata programmatically (https://www.drupal.org/node/3280569). I mentioned this above, but it seemed like a dead end because it only allowsadding metadata, notmodifying the one we want to change. @paul121's idea was to simplyadd an additional That feels like a good next step here. It means that this will depend on#980, though, so let's get that merged first. |
mstenta commentedOct 16, 2025
I tested this, but it does not do what we want. I can add meta key/values to |
mstenta commentedOct 16, 2025
I think the only other option to achieve this would be to patch Drupal core. And if we went that route we might as well patch both instances of I'm not sure this is important enough to justify maintaining another core patch. I'm going to mark this as "postponed" on the hope that others in the Drupal core community come up with a better way to do this, but it's not something I'm going to invest more time in right now... |
7cca39a toc991536Compare
This PR proposes changing
drupal_internal__*properties in the farmOS JSON:API tointernal__*, removing thedrupal_prefix.IMO there is no need to include
drupal_. A prefix ofinternal__*is enough to indicate that the properties are internal.The two main attributes that are affected by this are
drupal_internal__idanddrupal_internal__revision_id.Notably, there is one other instance of
drupal_internal__*that appears deeper in the JSON structures, which this PR currently does NOT fix. Somerelationshipsinclude ameta.drupal_internal__target_idto indicate the internal ID of the referenced entity. This appears underrelationshipslikeasset_type(and other similar ones likelog_type) anduid(but notably not in any of theentity_referencerelationships farmOS adds). Here is the Drupal core change record that added it:https://www.drupal.org/node/3218910The problem is that it is added in
\Drupal\jsonapi\JsonApiResource\ResourceIdentifier::toResourceIdentifier(), but there is no way to modify it from another module, and all JSON:API classes are marked as@internalwith an explicit warning:Drupal 11.2 included a new feature that allowsadding to high-level
metaproperties (https://www.drupal.org/project/drupal/issues/3100732), but it doesn't sound like this would help.@bradjones1 commented to this effect in an issue he created to propose allowing "opt-out of automatic meta.drupal_internal__target_id on entity relationships":https://www.drupal.org/project/drupal/issues/3257608#comment-14463720So... the question is: should we consider changing
drupal_internal__*tointernal_*in the high-level JSON:API resources, but leavedrupal_internal__target_idalone? Or try to find another (heavier-handed) way of fixing that case? Or should we just leavedrupal_internal__*and scrap this idea?This PR still needs tests, but I figure those will be pretty easy to add, if we decide this is worth pursuing.