From 5a158958f3b6267863aa420a2638be2bd7d6cb28 Mon Sep 17 00:00:00 2001 From: Lev Israel Date: Tue, 13 Jan 2026 22:49:39 -0500 Subject: [PATCH] fix: Be lazy about checking for empty text, to save operations --- api/views.py | 5 ++--- sefaria/model/text.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/api/views.py b/api/views.py index 0ae5921267..08e98fa91a 100644 --- a/api/views.py +++ b/api/views.py @@ -26,6 +26,8 @@ def split_piped_params(params_string) -> List[str]: return params def _handle_warnings(self, data): + if len(data['available_versions']) == 0 and not self.oref.index_node.is_virtual: + return jsonResponse({'error': f'We have no text for {self.oref}.'}, status=404) data['warnings'] = [] for lang, vtitle in data['missings']: if lang == 'source': @@ -43,9 +45,6 @@ def _handle_warnings(self, data): return data def get(self, request, *args, **kwargs): - if self.oref.is_empty() and not self.oref.index_node.is_virtual: - return jsonResponse({'error': f'We have no text for {self.oref}.'}, status=404) - versions_params = request.GET.getlist('version', []) if not versions_params: versions_params = ['primary'] diff --git a/sefaria/model/text.py b/sefaria/model/text.py index d9a30bc06a..d00462d217 100644 --- a/sefaria/model/text.py +++ b/sefaria/model/text.py @@ -3746,7 +3746,7 @@ def is_empty(self, lang=None): """ Checks if :class:`Ref` has any corresponding data in :class:`Version` records. - :return: Bool True is there is not text at this ref in any language + :return: Bool True is there is no text at this ref in any language """ # The commented code is easier to understand, but the code we're using puts a lot less on the wire.