Skip to content

Commit

Permalink
fix(Backend topic images): Remove custom exception, prefer assert
Browse files Browse the repository at this point in the history
  • Loading branch information
saengel committed Nov 20, 2023
1 parent c4f6170 commit f6b4d08
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
7 changes: 2 additions & 5 deletions sefaria/model/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .schema import AbstractTitledObject, TitleGroup
from .text import Ref, IndexSet, AbstractTextRecord
from .category import Category
from sefaria.system.exceptions import InputError, DuplicateRecordError, ExternalImageError
from sefaria.system.exceptions import InputError, DuplicateRecordError
from sefaria.model.timeperiod import TimePeriod, LifePeriod
from sefaria.model.portal import Portal
from sefaria.system.database import db
Expand Down Expand Up @@ -73,10 +73,7 @@ def _validate(self):
if getattr(self, 'subclass', False):
assert self.subclass in self.subclass_map, f"Field `subclass` set to {self.subclass} which is not one of the valid subclass keys in `Topic.subclass_map`. Valid keys are {', '.join(self.subclass_map.keys())}"
if getattr(self, 'image', False):
try:
self.image["image_uri"].index("https://storage.googleapis.com/img.sefaria.org/topics/")
except ExternalImageError:
print("The image is not stored properly. Topic should be stored in the image GCP bucket, in the topics subdirectory.")
assert "https://storage.googleapis.com/img.sefaria.org/topics/" in self.image["image_uri"], "The image is not stored properly. Topic should be stored in the image GCP bucket, in the topics subdirectory."

if getattr(self, 'portal_slug', None):
Portal.validate_slug_exists(self.portal_slug)
Expand Down
3 changes: 0 additions & 3 deletions sefaria/system/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class ManuscriptError(Exception):
class MissingKeyError(Exception):
pass

class ExternalImageError(Exception):
"""Thrown when an image is added to the database that is not hosted in our GCP bucket"""
pass

class SluggedMongoRecordMissingError(Exception):
pass
Expand Down

0 comments on commit f6b4d08

Please sign in to comment.