Scanner finds older paragraphs from node revisions

Created on 18 May 2024, 10 months ago

Problem/Motivation

Noticing a behaviour that leads to confusion for end users of this module.

The module, when configured for paragraphs, will locate old paragraphs that exist in older revisions of content. This leads to replacements that actually don't exist on the original node anymore.

Steps to reproduce

1. Drupal 10.2.6
2. Latest version of Scanner
3. Latest version of paragraphs
4. Create a new paragraph, single text field
5. Configure scanner to use this paragraph and the single text field
6. Add a new content type
7. Add an ERR field that can reference the new paragraph
8 Add a new node, populate the new paragraph text field
9. Save
10. Create a new revision of this node
11. Remove the original paragraph
12. Add a new paragraph
13. Add a string value
14. Save
15. Search for the string that exists in the first paragraph
16. The old paragraph surfaces in search
17. Replace the value

The old paragraph that existed in the first revision is updated with the new string, but the revision isn't used anywhere.

This is confusing, because if I search for the replacement string again it'll surface in search, but the node that exists in the search results has no reference to the found string, in any of its revisions.

Before replace

MariaDB [db]> select * from paragraphs_item_revision;
+----+-------------+----------+------------------+
| id | revision_id | langcode | revision_default |
+----+-------------+----------+------------------+
|  1 |           1 | en       |                1 |
|  2 |           2 | en       |                1 |
+----+-------------+----------+------------------+
2 rows in set (0.001 sec)

After replace

MariaDB [db]> select * from paragraphs_item_revision;
+----+-------------+----------+------------------+
| id | revision_id | langcode | revision_default |
+----+-------------+----------+------------------+
|  1 |           1 | en       |                1 |
|  2 |           2 | en       |                1 |
|  1 |           3 | en       |                1 | <--- new revision created by scanner
+----+-------------+----------+------------------+
3 rows in set (0.002 sec)

The node (before and after) - note no reference to the new paragraph revision

MariaDB [db]> select * from node_revision__field_components;
+-----------+---------+-----------+-------------+----------+-------+----------------------------+-------------------------------------+
| bundle    | deleted | entity_id | revision_id | langcode | delta | field_components_target_id | field_components_target_revision_id |
+-----------+---------+-----------+-------------+----------+-------+----------------------------+-------------------------------------+
| paragraph |       0 |         3 |           7 | en       |     0 |                          1 |                                   1 |
| paragraph |       0 |         3 |           8 | en       |     0 |                          2 |                                   2 |
+-----------+---------+-----------+-------------+----------+-------+----------------------------+-------------------------------------+

Proposed resolution

We could add an option to only search for 'live' paragraphs, but is there an argument this behaviour should ever locate old paragraphs on old revisions given the functionality of the module only creates a new paragraph revision and doesn't update the 'parent' (node) in any way.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom aaron.ferris

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

Comments & Activities

  • Issue created by @aaron.ferris
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    I think this is a major issue because it has risky and unexpected results. I agree only the actual content / latest revision should be touched here. Could you prepare a MR with a fix?

    Is the result the same with MR!1 from here: πŸ› Errors on search-only for deep-nested paragraphs Needs review ?

  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris

    I can prepare a MR sure, I implemented something for my use case, may not necessarily suit the wider module at this point but happy to showcase something thats working for me.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    @aaron.ferris did the linked issue resolve the problem? Wonder if this is a dup.

  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris

    Ill definitely check it out @smustgrave - thanks, if not ill add the patch ive been using on a project that seems to resolve the issue for me... ill hopefully get some time over the holidays to have a proper look.

  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris

    OK, managed to have a look at this - I don't believe this issue exists on 2.0.x

    1. Drupal 10.3
    2. Scanner 2.0 beta
    3. ERR 1.12
    4. Paragraphs 1.18

    No patches.

    1. Enable scanner, ERR, paragraphs
    2. Add a new paragraph with a single plain text field
    3. Add a Paragraphs field to the basic page content type, configure to allow the new paragraph
    4. Add a new basic page
    5. Add a paragraph, use 'old paragraph value' as the plain text field value
    6. Save the node
    7. Edit the node
    8. Remove the paragraph, add a new one
    9. Use 'new paragraph value' as the field value
    10. Search for 'old paragraph value' in scanner
    11. Expected: No results
    12. Actual: No results
    13. Search for 'new paragraph value' in scanner
    14. Expected: 1 result
    15. Actual: 1 result

    Ill setup with 1.x as well just to reconfirm that it still exists there.

  • πŸ‡¬πŸ‡§United Kingdom aaron.ferris

    I can confirm the general approach from https://www.drupal.org/project/scanner/issues/3196119 πŸ› Errors on search-only for deep-nested paragraphs Needs review does indeed resolve this issue and it follows a very similar approach to the patch I am using on a project (essentially a method to check if the found paragraph has a parent). I think we can close this as a duplicate.

    1. Drupal 10.3
    2. Scanner 2.0 beta
    3. ERR 1.12
    4. Paragraphs 1.18

    Approach from https://www.drupal.org/project/scanner/issues/3196119 πŸ› Errors on search-only for deep-nested paragraphs Needs review

    1. Setup as above
    2. Add a new paragraph with a string field
    3. Add a paragraphs field to the basic page content type, allow references to the new paragraph
    4. Add a new basic page
    5. Use 'old paragraph value' as the string
    6. Save
    7. Edit this node
    8. Remove the old paragraph, add a new one, use 'new paragraph value' as the field value
    9. Save
    10. In scanner, search for 'old paragraph value'
    11. Expected: 0 results
    12. Actual: 0 results
    13. Search for 'new paragraph value'
    11. Expected: 1 result
    12. Actual: 1 result

Production build 0.71.5 2024