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

Fix/raise integrity error like before #187

Merged
merged 2 commits into from
Sep 2, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions timely_beliefs/beliefs/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,6 @@ def add_to_session(
],
set_=dict(event_value=smt.excluded.event_value),
)
else:
smt = smt.on_conflict_do_nothing()

session.execute(smt)

Expand Down
30 changes: 4 additions & 26 deletions timely_beliefs/tests/test_belief_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,9 @@ def test_adding_to_session(
assert len(bdf) == len(new_bdf)


def test_adding_to_session_succeeds(
time_slot_sensor: DBSensor,
rolling_day_ahead_beliefs_about_time_slot_events,
):

# Retrieve some data from the database
bdf = DBTimedBelief.search_session(
session=session,
sensor=time_slot_sensor,
)

# Attempting to save the same data should not fail, even if we expunge everything from the session
try:
DBTimedBelief.add_to_session(
session,
bdf,
expunge_session=True,
bulk_save_objects=True,
commit_transaction=True,
)
except IntegrityError as exception:
raise pytest.fail("DID RAISE {0}".format(exception))


def test_adding_to_session_fails(
@pytest.mark.parametrize("bulk_save_objects", [False, True])
def test_fail_adding_to_session(
bulk_save_objects: bool,
time_slot_sensor: DBSensor,
rolling_day_ahead_beliefs_about_time_slot_events,
):
Expand All @@ -90,6 +68,6 @@ def test_adding_to_session_fails(
session,
bdf,
expunge_session=True,
bulk_save_objects=False,
bulk_save_objects=bulk_save_objects,
commit_transaction=True,
)
Loading