-
Notifications
You must be signed in to change notification settings - Fork 33
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix polymorphism in Translator #1346
Merged
marc-vanderwal
merged 2 commits into
zonemaster:develop
from
marc-vanderwal:bugfix/broken-translator-polymorphism
Jun 3, 2024
Merged
Fix polymorphism in Translator #1346
marc-vanderwal
merged 2 commits into
zonemaster:develop
from
marc-vanderwal:bugfix/broken-translator-polymorphism
Jun 3, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In Zonemaster::Backend, the codebase defines a Zonemaster::Backend::Translator class which inherits from Zonemaster::Engine::Translator, because it needs to override the translate_tag() method with a custom version. However, one change introduced in zonemaster-engine#1319 caused this inheritance to no longer work properly. The main symptom was that commands such as `zmb get_test_results`, that rely on translating messages pulled from the database, stopped working. The root cause of the problem is that when calling Zonemaster::Backend::Translator->new(), the newly-created instance was always blessed as Zonemaster::Engine::Translator (the superclass), not as the inheriting class. Thus, the translate_tag() method was always that of the superclass instead of the inheriting class. Hence the crash. Fixing this is easy, fortunately.
marc-vanderwal
added
T-Bug
Type: Bug in software or error in test case description
P-High
Priority: Issue to be solved before other
labels
May 15, 2024
In the "how to test" it should be |
That’s because it was a typo. I’ve fixed the procedure. |
The _build_all_tag_descriptions should be called using dynamic (polymorphic) dispatch. Backend has a Translator that inherits from the Engine’s Translator, and overrides _build_all_tag_descriptions to call this class’s method, then does some processing of its own. Without this change, some Backend-specific error messages will remain untranslated.
This was referenced May 15, 2024
marc-vanderwal
added
the
V-Patch
Versioning: The change gives an update of patch in version.
label
May 16, 2024
mattias-p
approved these changes
Jun 3, 2024
matsduf
approved these changes
Jun 3, 2024
Release testing for v2024.1I've tested this according to the testing instruction above with successful results. |
mattias-p
added
the
S-ReleaseTested
Status: The PR has been successfully tested in release testing
label
Jun 25, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
P-High
Priority: Issue to be solved before other
S-ReleaseTested
Status: The PR has been successfully tested in release testing
T-Bug
Type: Bug in software or error in test case description
V-Patch
Versioning: The change gives an update of patch in version.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
This PR fixes some regressions, presumably introduced by #1319, that could not be caught in Zonemaster::Engine’s unit tests.
Context
Problems
In Zonemaster::Backend, there is a
Zonemaster::Backend::Translator
class which inherits fromZonemaster::Engine::Translator
. This is done in order to override thetranslate_tag
method with a custom version.When “un-Moosing” Zonemaster::Engine, however, changes were introduced that were harmless for Zonemaster::Engine, but not for Zonemaster::Backend. This caused two issues to emerge:
zmb get_test_results
, that rely on translating messages pulled from the database, stopped working;Cause
The root cause of the first problem is that when calling
Zonemaster::Backend::Translator->new()
, the newly-created instance was always blessed as Zonemaster::Engine::Translator (the superclass), not as the inheriting class. Thus,translate_tag()
method calls always called the method in the superclass instead of the inheriting class.As for the second problem, this is due to Backend’s Translator overriding another method,
_build_all_tag_descriptions
, from Engine’s Translator, and the initialization code in Zonemaster::Engine::Translator failing to call the overridden_build_all_tag_description
when invoked as the Backend’s Translator class.Changes
__PACKAGE__
(a macro that always expands toZonemaster::Engine::Translator
), bless with$class
instead._build_all_tag_descriptions
subroutine a proper class method and haveinitialize
hand over to the method of the correct class.How to test this PR
Make sure Ensure Backend’s messages stay translated zonemaster-backend#1166 is merged first.
Run a test with
zmb
and grab the test ID (or have a test ID of a previous test handy and skip the following command):This command should print
"localhost"
(or whatever the domain under test was) and set an exit status of 0. Any other result, ornull
, is abnormal.zmtest
, run a test on a domain name that causes Zonemaster to time out, such aspool.ntp.org
. The error message stating that the test took too long to complete should be translated (i.e., the raw untranslated message tag must not appear).