Skip to content

Commit

Permalink
Fix error from type annotations containing ellipsis (#127)
Browse files Browse the repository at this point in the history
* Fix error from type annotations containing ellipsis

* Fix wrong number

---------

Co-authored-by: Jay Qi <[email protected]>
  • Loading branch information
jayqi and jayqi committed Sep 19, 2024
1 parent e77348e commit 3464382
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# erdantic Changelog

## v1.0.5 (Unreleased)

- Fixed runtime `AttributeError` that occurred when creating a diagram that includes a model with a field that uses a type annotation with ellipsis literal (e.g., `tuple[int, ...]`). ([Issue #124](https://github.com/drivendataorg/erdantic/issues/124), [PR #127](https://github.com/drivendataorg/erdantic/pull/127))

## v1.0.4 (2024-07-16)

- Fixed handling of `typing.Annotated` in cases where it's not the outermost generic type. ([Issue #122](https://github.com/drivendataorg/erdantic/issues/122), [PR #123](https://github.com/drivendataorg/erdantic/pull/123))
Expand Down
4 changes: 4 additions & 0 deletions erdantic/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ def _add_if_model(self, model: type, recurse: bool) -> bool:
# These are not going to be models
if "__qualname__" in str(e):
return False
# ellipsis object (used for example in tuple[int, ...]) don't have __module__ attribute
# This is also not going to be a model
elif "__module__" in str(e):
return False
raise
if key not in self.models:
try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "erdantic"
version = "1.0.4"
version = "1.0.5"
description = "Entity relationship diagrams for Python data model classes like Pydantic."
readme = "README.md"
authors = [{ name = "DrivenData", email = "[email protected]" }, { name = "Jay Qi" }]
Expand Down
14 changes: 13 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from pathlib import Path
import sys
from typing import Any, AnyStr, List, Literal, Optional, TypeVar
from typing import Any, AnyStr, List, Literal, Optional, Tuple, TypeVar

if sys.version_info >= (3, 9):
from typing import Annotated
Expand Down Expand Up @@ -200,6 +200,18 @@ class MyModel(pydantic.BaseModel):

diagram = EntityRelationshipDiagram()
diagram.add_model(MyModel)
diagram.to_dot()


def test_model_with_ellipsis():
"""Model with Ellipsis should not error."""

class EllipsisModel(pydantic.BaseModel):
ellipsis_field: Tuple[int, ...]

diagram = EntityRelationshipDiagram()
diagram.add_model(EllipsisModel)
diagram.to_dot()


def test_model_with_no_fields():
Expand Down

0 comments on commit 3464382

Please sign in to comment.