Skip to content

Commit

Permalink
fix(documentation): force read lazy objects as str
Browse files Browse the repository at this point in the history
The verbose names of models could be lazy objects, which should be
forced into str representation to avoid errors while creating the graph.

closes #1319
  • Loading branch information
gythaogg committed Oct 23, 2024
1 parent ff675bd commit a0f52bf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apis_core/documentation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import force_str

from apis_core.apis_entities.utils import get_entity_content_types

Expand Down Expand Up @@ -40,7 +41,7 @@ def edges(self):
ContentType.objects.get_for_model(subj_class).name,
ContentType.objects.get_for_model(obj_class).name,
)
edges[key].append(rel.model_class().name())
edges[key].append(force_str(rel.model_class().name()))
return edges

def make_graph(self):
Expand All @@ -52,7 +53,9 @@ def make_graph(self):
graph.set_graph_defaults(nodesep="1", ranksep="1", TBbalance="max")
for content_type in self.entities:
model_class = content_type.model_class()
node = Node(content_type.name, label=model_class._meta.verbose_name)
node = Node(
content_type.name, label=force_str(model_class._meta.verbose_name)
)
node.set_URL(model_class.get_listview_url())
node.set_fillcolor("#3399ff")
node.set_style("filled")
Expand Down

0 comments on commit a0f52bf

Please sign in to comment.