Page MenuHomePhabricator

tests moved to a different function still show on implementations of the original
Open, In Progress, LowPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?:

What should have happened instead?:
The test has actually been migrated to a different parent function (https://www.wikifunctions.org/view/en/Z26344) by editing the test (https://www.wikifunctions.org/w/index.php?title=Z25945&diff=203446&oldid=200199). So it should not show on implementation children of the original function it was at.

Event Timeline

Jdforrester-WMF added a project: WikiLambda.
Jdforrester-WMF subscribed.

Yes, moving Test cases to a different Function are still not supported, as discussed previously at length. :-)

However, this should have been caught by the refresh code.

Proposal: Prevent stale test–function relations when moving tests between functions

Summary

A test (Z20) that has been migrated to a different parent function can still appear as a test case of the original function. This happens because secondary tables and cached test results are not fully updated when the test’s function ZID is changed.

This proposal suggests:

  1. Enforcing a workflow rule: connected tests cannot be reassigned to a different function
  2. Ensuring secondary tables and cached test results are fully updated when tests are edited
  3. Simplifying rights handling by avoiding implicit disconnects

Technical background

Object relationships

  • Tests (Z20) are independent ZObjects.
  • A function only references tests when they are connected:
    • Connected tests appear in the function’s Z8K3 list
    • Implementations *never* mention tests directly

Secondary tables involved

  • Function → test (only when connected):
SELECT * FROM wikilambda_zobject_join
WHERE wlzo_related_type = 'Z20';
  • Test → function (always, connected or disconnected):
SELECT * FROM wikilambda_zobject_function_join
WHERE wlzf_type = 'Z20';

When a test’s function ZID changes, the edited object is the test, so ZObjectSecondaryDataUpdate::doUpdate() runs for the test. This should cover all necessary updates, but currently does not.

Cached test results

Test results are also cached in:

SELECT * FROM wikilambda_ztester_results
WHERE wlztr_ztester_zid = 'Z8500';

These entries are function-specific and must be purged or updated when a test moves to another function.

Findings from database inspection

  • wikilambda_ztester_results
    • Still contains rows with:
      • wlztr_ztester_zid = Z25945
      • wlztr_zfunction_zid = Z25930 (old function)
  • wikilambda_zobject_join
    • Still links:
      • wlzo_related_zobject = Z25945
      • wlzo_main_zid = Z25930 (old function)
  • wikilambda_zobject_function_join
    • Correctly links Z25945 to the new function (Z26344)

Identifiers for clarity:

  • Tester: Z25945
  • Incorrect:
    • Function: Z25930
    • Implementation: Z26305
  • Correct:
    • Function: Z26344
    • Implementation: Z26345

Rights and workflow concerns

Moving a connected test from one function to another implicitly requires:

  • Disconnect rights (to remove it from the original function)
  • Edit rights (to modify the test)

This introduces complex permission checks and potentially two implicit edits:

  1. Disconnecting the test from the old function
  2. Editing the test to point to a new function

This complexity is error-prone and difficult to reason about.

Proposed solution

Enforce a clear rule

When changing the parent function of a test or implementation:

  • If the object is connected to its current function:
    • Reject the edit
    • Return an error message such as:
This test is currently connected to a function.
Please disconnect it from the original function before assigning it to a new one.

Benefits

  • Avoids implicit disconnect edits
  • Avoids complex permission intersections
  • Ensures the test is always disconnected when reassigned
  • Guarantees that only secondary table updates are required
  • Makes user intent explicit and predictable

Required updates after edit (when disconnected)

  • Update:
    • wikilambda_zobject_function_join
  • Ensure no stale entries remain in:
    • wikilambda_zobject_join
    • wikilambda_ztester_results

Conclusion

By enforcing that tests and implementations must be disconnected before reassignment we simplify permissions, prevent stale secondary data, and avoid inconsistent UI behavior. This rule aligns with the current data model and avoids multi-object implicit edits.

Additional scope: implementations

The same issue also occurs when changing the parent function of an implementation (Z14).

Like tests (Z20), implementations are independent objects that may be connected to a function. If the function ZID inside an implementation is changed while it is still connected, stale relations and cached data can remain, causing the implementation to appear under the wrong function.

Therefore, the proposed rule must apply to both tests and implementations:

  • When changing the parent function of a test (Z20) or implementation (Z14)
  • If it is currently connected, reject the edit and require an explicit disconnect first

This avoids implicit disconnects, simplifies permissions, and keeps secondary data consistent.

DSmit-WMF changed the task status from Open to In Progress.Dec 19 2025, 10:53 AM
DSmit-WMF claimed this task.

Message being implemented when trying to change a function of a tester that is still connected:

Screenshot 2026-01-08 at 12.17.03.png (1×1 px, 162 KB)

Adding a maintenance script to fix in prod:

Screenshot 2026-01-15 at 15.14.45.png (1×1 px, 543 KB)

Change #1227344 had a related patch set uploaded (by Daphne Smit; author: Daphne Smit):

[mediawiki/extensions/WikiLambda@master] Add a maintenance script to fix two types of issues with function tester and implementation lists:

https://gerrit.wikimedia.org/r/1227344

What it will look like in history of a function which Z8K3/Z8K4 have been changed

Screenshot 2026-01-15 at 12.51.49.png (732×2 px, 263 KB)

As a bonus this will also fix duplicates and deleted testers/imps;)

Change #1227748 had a related patch set uploaded (by Daphne Smit; author: Daphne Smit):

[operations/mediawiki-config@master] [wikifunctions] Grant sysops permission to edit function of attached implementation and tester

https://gerrit.wikimedia.org/r/1227748

@DSmit-WMF: Train wmf.12, including this patch, has rolled to production; please check and verify if this is fixed.

Note that the maintenance script hasn't landed yet so can't be run.

Change #1227344 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] Add a maintenance script to fix two types of issues with function tester and implementation lists:

https://gerrit.wikimedia.org/r/1227344

Mentioned in SAL (#wikimedia-operations) [2026-01-29T14:08:46Z] <James_F> Running mwscript-k8s -f -- extensions/WikiLambda/maintenance/fixFunctionTesterImplementationIssues.php --wiki=wikifunctionswiki for T399934

Maintenance script run results:

Step 1: Checking for testers/implementations referenced by multiple functions...
Found 17 tester(s)/implementation(s) referenced by multiple functions.
Z11638 (tester): should be in Z11637, removing from: Z11786
Z11639 (implementation): should be in Z11637, removing from: Z11786
Z11734 (tester): should be in Z11834, removing from: Z11722
Z11735 (tester): should be in Z11834, removing from: Z11722
Z11736 (tester): should be in Z11834, removing from: Z11722
Z11737 (tester): should be in Z11834, removing from: Z11722
Z11769 (tester): should be in Z11834, removing from: Z11722
Z17955 (implementation): should be in Z17954, removing from: Z17956
Z18382 (tester): should be in Z18364, removing from: Z18386
Z18383 (implementation): should be in Z18364, removing from: Z18386
Z18385 (tester): should be in Z18364, removing from: Z18386
Z18931 (tester): should be in Z14311, removing from: Z14310
Z21528 (tester): should be in Z12665, removing from: Z21028
Z21529 (tester): should be in Z12665, removing from: Z21028
Z21530 (tester): should be in Z12665, removing from: Z21028
Z220 (implementation): should be in Z120, removing from: Z123
Z25945 (tester): should be in Z26344, removing from: Z25930

Processing 3582 function(s) in batches of 100...
Step 2: Fixing duplicates within function lists...
Step 3: Removing non-existent testers/implementations...
Processing batch: 1-100 of 3582...
Z10070: Maintenance: removed 2 duplicate tester(s)
  Removed tester ZIDs: Z16040, Z19124
Z10215: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z16063
Z10251: Maintenance: removed 2 duplicate tester(s)
  Removed tester ZIDs: Z10255, Z10256
Processing batch: 101-200 of 3582...
Z10459: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z10471
Z10539: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z16039
Processing batch: 201-300 of 3582...
Processing batch: 301-400 of 3582...
Processing batch: 401-500 of 3582...
Processing batch: 501-600 of 3582...
Processing batch: 601-700 of 3582...
Z13445: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z13458
Z13522: Maintenance: removed 2 duplicate tester(s)
  Removed tester ZIDs: Z14157
Processing batch: 701-800 of 3582...
Z13927: Maintenance: removed 1 duplicate implementation(s)
  Removed implementation ZIDs: Z13941
Processing batch: 801-900 of 3582...
Z14226: Maintenance: removed 1 non-existent tester(s)
  Removed non-existent tester ZIDs: Z14234
Processing batch: 901-1000 of 3582...
Processing batch: 1001-1100 of 3582...
Processing batch: 1101-1200 of 3582...
Z16172: Maintenance: removed 1 non-existent tester(s)
  Removed non-existent tester ZIDs: Z16178
Processing batch: 1201-1300 of 3582...
Processing batch: 1301-1400 of 3582...
Z17783: Maintenance: removed 3 duplicate tester(s)
  Removed tester ZIDs: Z17785, Z17786, Z17787
Processing batch: 1401-1500 of 3582...
Z18515: Maintenance: removed 1 non-existent tester(s)
  Removed non-existent tester ZIDs: Z18521
Processing batch: 1501-1600 of 3582...
Z18828: Maintenance: removed 1 duplicate implementation(s)
  Removed implementation ZIDs: Z18830
Z18877: Maintenance: removed 2 duplicate implementation(s)
  Removed implementation ZIDs: Z18878
Z18988: Maintenance: removed 1 non-existent implementation(s)
  Removed non-existent implementation ZIDs: Z18992
Z19343: Maintenance: removed 1 duplicate implementation(s)
  Removed implementation ZIDs: Z21084
Processing batch: 1601-1700 of 3582...
Z19565: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z19569
Z19629: Maintenance: removed 1 duplicate implementation(s)
  Removed implementation ZIDs: Z19630
Processing batch: 1701-1800 of 3582...
Z20323: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z20330
Processing batch: 1801-1900 of 3582...
Z21121: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z21190
Processing batch: 1901-2000 of 3582...
Z21245: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z21257
Processing batch: 2001-2100 of 3582...
Processing batch: 2101-2200 of 3582...
Processing batch: 2201-2300 of 3582...
Z23407: Maintenance: removed 2 duplicate tester(s)
  Removed tester ZIDs: Z23409, Z23412
Processing batch: 2301-2400 of 3582...
Processing batch: 2401-2500 of 3582...
Z24290: Maintenance: removed 1 duplicate implementation(s)
  Removed implementation ZIDs: Z24297
Processing batch: 2501-2600 of 3582...
Z25286: Maintenance: removed 1 duplicate tester(s)
  Removed tester ZIDs: Z25293
Processing batch: 2601-2700 of 3582...
Processing batch: 2701-2800 of 3582...
Processing batch: 2801-2900 of 3582...
Processing batch: 2901-3000 of 3582...
Processing batch: 3001-3100 of 3582...
Processing batch: 3101-3200 of 3582...
Processing batch: 3201-3300 of 3582...
Processing batch: 3301-3400 of 3582...
Processing batch: 3401-3500 of 3582...
Processing batch: 3501-3582 of 3582...

Fixed 41 function(s).

Edits indeed made successfully, like https://www.wikifunctions.org/w/index.php?title=Z14310&curid=26563&diff=247332&oldid=206056

I re-ran the script and it was a no-op. Success!

Change #1235038 had a related patch set uploaded (by Jforrester; author: Jforrester):

[mediawiki/extensions/WikiLambda@master] maintenance: Drop one-off fixFunctionTesterImplementationIssues

https://gerrit.wikimedia.org/r/1235038

Change #1235038 merged by jenkins-bot:

[mediawiki/extensions/WikiLambda@master] maintenance: Drop one-off fixFunctionTesterImplementationIssues

https://gerrit.wikimedia.org/r/1235038