Skip to content

Commit

Permalink
fix json
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Oct 17, 2024
1 parent dc97f10 commit c4ab3bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions pioreactor/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from time import sleep

import pytest
from msgspec.json import encode as dumps

from pioreactor.background_jobs.stirring import start_stirring
from pioreactor.pubsub import subscribe_and_callback
Expand Down Expand Up @@ -322,6 +323,22 @@ def test_upsert_setting_insert(job_manager, job_id):
assert result[0] == value


def test_upsert_setting_insert_complex_types(job_manager, job_id):
setting = "settingDict"
value = {"A": 1, "B": {"C": 2}}

# Call the upsert_setting function
job_manager.upsert_setting(job_id, setting, value)

# Verify the setting was inserted correctly
job_manager.cursor.execute(
"SELECT value FROM pio_job_published_settings WHERE job_id=? AND setting=?", (job_id, setting)
)
result = job_manager.cursor.fetchone()
assert result is not None
assert result[0] == dumps(value).decode() == r'{"A":1,"B":{"C":2}}'


def test_upsert_setting_update(job_manager, job_id):
# First insert a setting-value pair
setting = "setting1"
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def upsert_setting(self, job_id: JobMetadataKey, setting: str, value: Any) -> No
UPDATE SET value = :value;
"""
if isinstance(value, dict):
value = dumps(value)
value = dumps(value).decode() # back to string, not bytes
else:
value = str(value)

Expand Down

0 comments on commit c4ab3bf

Please sign in to comment.