Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DB] Improve conflict error message #1252

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mlrun/api/db/sqldb/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ def _try_commit_obj():
# We want to retry only when database is locked so for any other scenario escalate to fatal failure
try:
raise mlrun.errors.MLRunConflictError(
f"Conflict - {cls} already exists"
f"Conflict - {cls} already exists: {obj.get_identifier_string()}"
) from err
except mlrun.errors.MLRunConflictError as exc:
raise mlrun.utils.helpers.FatalFailureException(
Expand Down
33 changes: 33 additions & 0 deletions mlrun/api/db/sqldb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class Artifact(Base, HasStruct):
body = Column(BLOB)
labels = relationship(Label)

def get_identifier_string(self) -> str:
return f"{self.project}/{self.key}/{self.uid}"

class Function(Base, HasStruct):
__tablename__ = "functions"
__table_args__ = (
Expand All @@ -161,6 +164,9 @@ class Function(Base, HasStruct):
updated = Column(TIMESTAMP)
labels = relationship(Label)

def get_identifier_string(self) -> str:
return f"{self.project}/{self.name}/{self.uid}"

class Log(Base, BaseModel):
__tablename__ = "logs"

Expand All @@ -170,6 +176,9 @@ class Log(Base, BaseModel):
# TODO: change to JSON, see mlrun/api/schemas/function.py::FunctionState for reasoning
body = Column(BLOB)

def get_identifier_string(self) -> str:
return f"{self.project}/{self.uid}"

class Run(Base, HasStruct):
__tablename__ = "runs"
__table_args__ = (
Expand All @@ -189,6 +198,9 @@ class Run(Base, HasStruct):
start_time = Column(TIMESTAMP)
labels = relationship(Label)

def get_identifier_string(self) -> str:
return f"{self.project}/{self.uid}/{self.iteration}"

class Schedule(Base, BaseModel):
__tablename__ = "schedules_v2"
__table_args__ = (UniqueConstraint("project", "name", name="_schedules_v2_uc"),)
Expand All @@ -209,6 +221,9 @@ class Schedule(Base, BaseModel):
labels = relationship(Label, cascade="all, delete-orphan")
concurrency_limit = Column(Integer, nullable=False)

def get_identifier_string(self) -> str:
return f"{self.project}/{self.name}"

@property
def scheduled_object(self):
return pickle.loads(self.struct)
Expand Down Expand Up @@ -262,6 +277,9 @@ class Project(Base, BaseModel):

labels = relationship(Label, cascade="all, delete-orphan")

def get_identifier_string(self) -> str:
return f"{self.name}"

@property
def full_object(self):
if self._full_object:
Expand All @@ -282,6 +300,9 @@ class Feature(Base, BaseModel):
Label = make_label(__tablename__)
labels = relationship(Label, cascade="all, delete-orphan")

def get_identifier_string(self) -> str:
return f"{self.project}/{self.name}"

class Entity(Base, BaseModel):
__tablename__ = "entities"
id = Column(Integer, primary_key=True)
Expand All @@ -293,6 +314,9 @@ class Entity(Base, BaseModel):
Label = make_label(__tablename__)
labels = relationship(Label, cascade="all, delete-orphan")

def get_identifier_string(self) -> str:
return f"{self.project}/{self.name}"

class FeatureSet(Base, BaseModel):
__tablename__ = "feature_sets"
__table_args__ = (
Expand All @@ -317,6 +341,9 @@ class FeatureSet(Base, BaseModel):
features = relationship(Feature, cascade="all, delete-orphan")
entities = relationship(Entity, cascade="all, delete-orphan")

def get_identifier_string(self) -> str:
return f"{self.project}/{self.name}/{self.uid}"

@property
def full_object(self):
if self._full_object:
Expand Down Expand Up @@ -347,6 +374,9 @@ class FeatureVector(Base, BaseModel):

labels = relationship(Label, cascade="all, delete-orphan")

def get_identifier_string(self) -> str:
return f"{self.project}/{self.name}/{self.uid}"

@property
def full_object(self):
if self._full_object:
Expand All @@ -368,6 +398,9 @@ class MarketplaceSource(Base, BaseModel):

_full_object = Column("object", JSON)

def get_identifier_string(self) -> str:
return f"{self.project}/{self.name}"

@property
def full_object(self):
if self._full_object:
Expand Down
6 changes: 4 additions & 2 deletions tests/api/utils/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ async def test_create_schedule_failure_already_exists(
cron_trigger,
)

with pytest.raises(mlrun.errors.MLRunConflictError) as excinfo:
with pytest.raises(
mlrun.errors.MLRunConflictError,
match=rf"Conflict - Schedule already exists: {project}/{schedule_name}",
):
scheduler.create_schedule(
db,
mlrun.api.schemas.AuthInfo(),
Expand All @@ -332,7 +335,6 @@ async def test_create_schedule_failure_already_exists(
do_nothing,
cron_trigger,
)
assert "Conflict - Schedule already exists" in str(excinfo.value)


@pytest.mark.asyncio
Expand Down