Editing a path alias on the server to point elsewhere causes a broken state with aliases on the client on pull

Created on 27 January 2025, 9 months ago

Problem/Motivation

When a URL alias entity is updated to point to a new entity, pulling the new entity causes two URL aliases with the same alias on the client site.

The use case for this is a content editor wanting to make a completely new section of the site on a staging server, with different nodes but preserving the URLs of the original. For example, a basic page node at /foo might be getting replaced with a larger content section made up of multiple nodes, with a landing page node now at the path /foo.

Steps to reproduce

Set up an import configuration with the Path alias processor, so that URL aliases are imported with nodes. Set up a server and client to pull a particular node type.

1. On the server, create a node and give it a path alias such as '/foo'
2. On the client, pull this node. The node on the client has the alias.
3. On the server, create a new node.
4. On the server, go to /admin/config/search/path and edit the /foo alias so its system path is the new node.
5. On the client, pull the new node.

The result is that there are now *two* path aliases on the client site, with the same alias. This can be seen

- in the path_alias table
- in the links at /admin/content, although those will also be affected by this core caching bug: 🐛 AliasPathProcessor doesn't add cacheability for the path alias entity Active

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @joachim
  • 🇬🇧United Kingdom joachim
  • 🇬🇧United Kingdom joachim

    This changes the path alias processor to handle path aliases as entities.

    The fact that the core path alias field sort of and sort of isn't a reference field makes it a bit more complicated than the entity reference processor.

    I've added a base class for kernel tests too.

  • Status changed to Needs work 3 months ago
  • 🇮🇹Italy Bladedu Italy

    Hi Joachim, I've tested this MR testing the scenario described here: https://www.drupal.org/project/entity_share/issues/3107278#comment-14282136 💬 Call to a member function getAlias on null Fixed and I received a fatal error as following
    NOTICE: PHP message: Uncaught PHP Exception Exception: "The path_alias ID 1 given by node with UUID 8084220c-b00f-481c-8302-ee333e05b081 was not found on the server or was not accessible." at /var/www/html/web/modules/contrib/entity_share/modules/entity_share_client/src/Plugin/EntityShareClient/Processor/PathAliasProcessor.php line 193

  • 🇬🇧United Kingdom joachim

    I don't really follow your steps to reproduce, sorry.
    Could you repost them here, and use meaningful labels for client / server as I can't keep track of 'SA' and 'SB'!

    Also, if you could debug to see why the JSONAPI request isn't querying for the right thing, that would be a big help.

  • 🇮🇹Italy Bladedu Italy

    I strongly advice to read that old discussion to get acquainted with the general issue and the Drupal core.

    To easy the steps to reproduce the bug I will describe here with more "talking labels"

    setup

    To start with we got 2 Drupal websites with path module from coreinstalled: one on server side which will simply call server and it is where entity_share_server is installed and running.
    The other Drupal instance would be client with simply entity_share_client installed.

    ON client instance we have two node content types: blog and remote_event
    ON server instance we only have the content type remote_event and both client and server share the same structure.

    The entity remote_event will be the one in share between the sites (on server side we create a channel for it).
    Last thing: create a remote entity and activate the path processor.

    steps

    1. create a node of type blog and choose a random path alias
    2. create a node of type remote_event on server and assign a random path alias
    3. O client pull the remote_event entity created and it will trigger the exception described above

    Please let me know if that helps.

  • 🇬🇧United Kingdom joachim

    I thought the steps on the other issue included deleting an entity?

  • 🇮🇹Italy Bladedu Italy

    Hi Joachim, no that scenario was not for deletion, but for the creation of path aliases when an entity has been syncronized and the path alias has to be created.

    Yesterday I made a few more tests with xdebug active and I noticed that the problem was elsewhere.I had to grant Administer URL aliases permission to the user role that has access to jsonapi.

    I saw you are the maintainer of https://www.drupal.org/project/path_alias_view_access . I guess we're forcing a new dependency here to make this work without granting admin permissions to possibly limited roles.

    I will give few more shots now I know this and see if I can cover all scenarios (and unlock the translation issue)

  • 🇬🇧United Kingdom joachim

    Yup, I made https://www.drupal.org/project/path_alias_view_access for this use case, so the admin permission doesn't need to be granted to the Entity Share API role.

  • 🇮🇹Italy Bladedu Italy

    Wouldn't be better to force the dependency of this module in the info file of entity_share_server?

    Maybe we should also document somewhere about this little thing. it took me a bit before understanding what was going on.

  • 🇬🇧United Kingdom joachim

    > Wouldn't be better to force the dependency of this module in the info file of entity_share_server?

    No, because you might not be using that processor at all.

    It's documented here:

    > * description = @Translation("Prepares entity with the right path alias information. The client authorization needs to have access to view path alias entities on the server: the Path Alias View Access module may be used for this."),

    and in the README:

    > * The path alias processor requires client authorization needs to have access to
    view path alias entities on the server. The [Path Alias View Access
    module]( https://www.drupal.org/project/path_alias_view_access ) may be used for
    this.

  • 🇮🇹Italy Bladedu Italy

    Ok thank you. I'd say it works. I cannot find anything wrong with it.

    I've also checked the scenario described in this issue https://www.drupal.org/project/entity_share/issues/3416720 🐛 Problem with "Path alias processor" together with translatable entities Active and, as you suggested, it did solve the issue.

Production build 0.71.5 2024