Skip to content

MagicMapper circular-construction guard — investigate root cause and remove guard #1564

Open

Description

@rubenvdlinde

Context

lib/Db/MagicMapper.php:337-348 contains a static counter + guard that bails out of `__construct()` without calling `initializeHandlers()` when the third instantiation happens within a request:

```php
self::$constructCount++;
if (self::$constructCount > 2) {
// Guard against the circular-construction case
$this->logger->warning(...);
return;
}
$this->initializeHandlers();
```

When the guard trips, the mapper exists but is unusable — every subsequent method call hits a null handler. That's better than infinite recursion, but it suggests there's a real circular DI graph somewhere that should be fixed at the source.

What this PR fixed

Removed two debug `file_put_contents('/tmp/or-debug.log', ...)` calls that were silently writing to disk and (more visibly) triggering "Permission denied" PHP warnings during test runs — see test output mention in PR #1563 (the upstream-quality-cleanup PR that filed this issue). The guard itself is left in place because removing it could trigger the underlying circular case.

What needs investigating

  1. Reproduce the third-construction scenario locally — when does MagicMapper get instantiated 3+ times in a single request?
  2. Trace the circular path: which dependency of MagicMapper transitively re-instantiates MagicMapper?
  3. Break the cycle properly (lazy DI / interface / factory)
  4. Remove the static counter + guard once the root cause is fixed

Acceptance criteria

  • Document the dependency cycle that necessitated the guard
  • Apply structural fix (likely `Closure` lazy resolution or a dedicated factory for the cyclic dep)
  • Delete `self::$constructCount` field, the guard, and the warning log
  • Test that the previously-cyclic instantiation path now works

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions