From f7a7f62f41e2ef21ddd046d36878eddf4ef77acd Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Tue, 22 Oct 2024 14:55:17 -0400 Subject: [PATCH] Avoid an extra exists() query --- arches/app/models/graph.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arches/app/models/graph.py b/arches/app/models/graph.py index 3a2eae245d..a531ee953d 100644 --- a/arches/app/models/graph.py +++ b/arches/app/models/graph.py @@ -2302,14 +2302,10 @@ def validate_fieldname(fieldname, fieldnames): .filter(slug=self.slug) ) if ( - graphs_with_matching_slug.exists() - and graphs_with_matching_slug[0].graphid != self.graphid - ): + first_matching_graph := graphs_with_matching_slug.first() + ) and first_matching_graph.graphid != self.graphid: if self.source_identifier_id: - if ( - self.source_identifier_id - != graphs_with_matching_slug[0].graphid - ): + if self.source_identifier_id != first_matching_graph.graphid: raise GraphValidationError( _( "Another resource model already uses the slug '{self.slug}'"