Skip to content

Adds failing test for cleared foreignkey behaviour#744

Draft
alexalligator wants to merge 2 commits intowagtail:mainfrom
Funbit-AS:cleared_foreignkey
Draft

Adds failing test for cleared foreignkey behaviour#744
alexalligator wants to merge 2 commits intowagtail:mainfrom
Funbit-AS:cleared_foreignkey

Conversation

@alexalligator
Copy link
Copy Markdown
Contributor

This PR adds a failing test to demonstrate the issue described below.

Ref slack discussion.

Wagtail localize currently skips extracting segments for optional foreign keys that have no instance set. I.e. cleared foreign keys are treated as a lack of meaningful data, rather than None being treated as a meaningful value in and of itself.

# From extract.py

elif isinstance(field, models.ForeignKey):
    # ... 

    related_instance = getattr(instance, field.name)
    if related_instance:
        segments.append(
            RelatedObjectSegmentValue.from_instance(
                field.name, related_instance
            )
        )

This means that once a page is translated, clearing the field on the source page and retranslating leaves the translation with a value still selected:

  • [OK] If you publish a source page with a chosen snippet, you see this reflected in the translation UI and the library correctly points the translated page to the localised version of the snippet.
  • [OK] Update source page with a different snippet instance and resync; the translation UI is updated and the translated page points to the localised version of the new snippet instance.
  • [WRONG?] Update the source page to nullify snippet instance choice (my_snippet=None). The foreign key disappears from the translation UI and the translated page is left pointing to the previous localised snippet instance when it should be set to None as well (in my opinion).

@zerolab
Copy link
Copy Markdown
Collaborator

zerolab commented Dec 6, 2023

The tests are failing with

test_post_update_page_translation_with_publish_translations_and_cleared_foreignkey
      self.assertEqual(self.fr_blog_post.test_snippet, None)
  AssertionError: <TestSnippet: TestSnippet object (2)> != None

as intended to show in the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants