Skip to content

Conversation

@dimitri-yatsenko
Copy link
Member

Summary

Fixes intermittent TypeError when generating diagrams with dj.Diagram(schema).

Problem

dj.Diagram(schema) could fail with:

TypeError: '_ClassNamespace' object is not iterable

This occurred when inspect.getmembers() encountered modules containing objects with non-standard __bases__ attributes (like _ClassNamespace from typing internals).

Root Cause

In lookup_class_name(), only ImportError was caught:

try:
    nodes.append(dict(context=dict(inspect.getmembers(member)), ...))
except ImportError:  # TypeError not caught!
    pass

Fix

Catch TypeError in addition to ImportError:

except (ImportError, TypeError):
    pass  # could not inspect module members, skip

Impact

  • No behavior change for working cases
  • Fixes edge cases where unusual modules (typing, metaclasses) are in context
  • Defensive fix - just skips problematic modules and continues search

Closes

🤖 Generated with Claude Code

When inspect.getmembers() encounters modules with objects that have
non-standard __bases__ attributes (like _ClassNamespace from typing
internals), it raises TypeError. This caused dj.Diagram(schema) to
fail intermittently depending on what modules were imported.

Now catches TypeError in addition to ImportError, allowing the search
to continue by skipping problematic modules.

Fixes #1072

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added bug Indicates an unexpected problem or unintended behavior enhancement Indicates new improvements labels Jan 9, 2026
@dimitri-yatsenko dimitri-yatsenko merged commit 5f2847c into pre/v2.0 Jan 9, 2026
8 checks passed
@dimitri-yatsenko dimitri-yatsenko deleted the fix/1072 branch January 9, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Indicates an unexpected problem or unintended behavior enhancement Indicates new improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants