Skip to content
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
5 changes: 4 additions & 1 deletion ravendb/http/request_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,10 @@ def __create_request(self, node: ServerNode, command: RavenCommand) -> Optional[
request = command.create_request(node)
# todo: optimize that if - look for the way to make less ifs each time
if request.data and not isinstance(request.data, str) and not inspect.isgenerator(request.data):
request.data = json.dumps(request.data, default=self.conventions.json_default_method)
# Making sur that all documents are utf-8 decoded, avoiding any bizzar caracters in the database documents
request.data = json.dumps(
request.data, default=self.conventions.json_default_method, ensure_ascii=False
).encode("utf-8")

# todo: 1117 - 1133
return request or None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
from ravendb.tools.utils import Utils


class Article:
def __init__(
self,
Id: str = None,
title: str = None,
):
self.Id = Id
self.title = title


class TestPutDocumentCommand(TestBase):
def setUp(self):
super().setUp()
Expand All @@ -27,9 +37,9 @@ def test_can_put_document_using_command(self):
loaded_user = session.load("users/1", User)
self.assertEqual(loaded_user.name, "Gracjan")

@unittest.skip("todo: Not passing on CI/CD")
# @unittest.skip("todo: Not passing on CI/CD")
def test_can_put_document_using_command_with_surrogate_pairs(self):
name_with_emojis = "Gracjan \ud83d\ude21\ud83d\ude21\ud83e\udd2c\ud83d\ude00😡😡🤬😀"
name_with_emojis = "Gracjan 😡😡🤬😀"

user = User(name=name_with_emojis, age=31)
node = Utils.entity_to_dict(user, self.store.conventions.json_default_method)
Expand All @@ -45,3 +55,21 @@ def test_can_put_document_using_command_with_surrogate_pairs(self):
with self.store.open_session() as session:
loaded_user = session.load("users/2", User)
self.assertEqual(loaded_user.name, name_with_emojis)

def test_can_put_document_using_command_with_utf_8_chars(self):
title_with_emojis = (
"Déposer un CAPITAL SOCIAL : ce que tu dois ABSOLUMENT comprendre avant de lancer une ENTREPRISE 🏦"
)

article = Article(title=title_with_emojis)
node = Utils.entity_to_dict(article, self.store.conventions.json_default_method)
command = PutDocumentCommand("articles/1", None, node)
self.store.get_request_executor().execute_command(command)

result = command.result

self.assertIsNotNone(result.change_vector)

with self.store.open_session() as session:
loaded_article = session.load("articles/1", Article)
self.assertEqual(loaded_article.title, title_with_emojis)