Skip to content

Commit

Permalink
RDBC-856 Decrease client complexity, enhance code clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
poissoncorp committed Jun 17, 2024
1 parent e246568 commit 09b6a08
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 461 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Dict, Type, TypeVar, Optional
from typing import Dict, Type, TypeVar, Optional, Any, Union

from ravendb.primitives import constants
from ravendb.documents.conventions import DocumentConventions
Expand Down Expand Up @@ -60,11 +60,11 @@ def get_single_value(

key: str = item.get("Key")
index: int = item.get("Index")
raw: dict = item.get("Value")
raw: Dict[str, Union[Any, Dict[str, Any]]] = item.get("Value")
if not raw:
return CompareExchangeValue(key, index, None)
metadata = None
bjro = raw.get(constants.Documents.Metadata.KEY)
bjro: Dict[str, Any] = raw.get(constants.Documents.Metadata.KEY)
if bjro:
metadata = (
MetadataAsDictionary(bjro)
Expand Down
2 changes: 1 addition & 1 deletion ravendb/documents/queries/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def write(self, obj: object):
elif "__str__" in obj.__class__.__dict__:
self.__buffer.append(str(obj))
else:
self.__buffer.append(str(Utils.dictionarize(obj)))
self.__buffer.append(str(Utils.object_to_dict_for_hash_calculator(obj)))

def write_parameters(self, qp: "Parameters") -> None:
if qp is None:
Expand Down
20 changes: 9 additions & 11 deletions ravendb/documents/session/entity_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,8 @@ def convert_to_entity(
if "from_json" in object_type.__dict__ and inspect.ismethod(object_type.from_json):
# By custom defined 'from_json' serializer class method
entity = object_type.from_json(document_deepcopy)
elif is_projection:
entity = DynamicStructure(**document_deepcopy)
entity.__class__ = object_type
try:
entity = Utils.initialize_object(document_deepcopy, object_type)
except TypeError as e:
raise InvalidOperationException("Probably projection error", e)
else:
entity = Utils.convert_json_dict_to_object(document_deepcopy, object_type)
entity = Utils.convert_json_dict_to_object(document_deepcopy, object_type, is_projection)

EntityToJsonUtils.invoke_after_conversion_to_entity_event(session, key, object_type, document_deepcopy)

Expand Down Expand Up @@ -295,10 +288,15 @@ def determine_object_type(

# Passed type is not a type from metadata, neither there's no inheritance - probably projection
elif object_type_from_user is not object_type_from_metadata:
if not all([name in object_type_from_metadata.__dict__ for name in object_type_from_user.__dict__]):
# Document from database and object_type from user aren't compatible
# Check if types are compatible
incompatible_fields = Utils.check_valid_projection(object_type_from_user, object_type_from_metadata)
if incompatible_fields:
raise exceptions.InvalidOperationException(
f"Cannot covert document from type {object_type_from_metadata} to {object_type_from_user}"
f"Invalid projection. Cannot covert document "
f"from type '{object_type_from_metadata.__name__}' "
f"to type '{object_type_from_user.__name__}'. "
f"Type '{object_type_from_user.__name__}' instance has fields {incompatible_fields} "
f"that aren't on '{object_type_from_metadata.__name__}'."
)

# Projection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_can_get_revisions_by_change_vector(self):

for i in range(10):
with self.store.open_session() as session:
user = session.load(id_, Company)
user = session.load(id_, User)
user.name = f"Fitzchak{i}"
session.save_changes()

Expand Down Expand Up @@ -134,7 +134,7 @@ def test_collection_case_sensitive_test_1(self):

for i in range(10):
with self.store.open_session() as session:
user = session.load(id_, Company)
user = session.load(id_, User)
user.name = "raven" + str(i)
session.save_changes()

Expand All @@ -159,7 +159,7 @@ def test_collection_case_sensitive_test_2(self):

for i in range(10):
with self.store.open_session() as session:
user = session.load(id_, Company)
user = session.load(id_, User)
user.name = "raven" + str(i)
session.save_changes()

Expand Down Expand Up @@ -284,7 +284,7 @@ def test_can_get_metadata_for_lazily(self):

for i in range(10):
with self.store.open_session() as session:
user = session.load(id_, Company)
user = session.load(id_, User)
user.name = f"Omer{i}"
session.save_changes()

Expand Down Expand Up @@ -319,7 +319,7 @@ def test_can_get_for_lazily(self):

for i in range(10):
with self.store.open_session() as session:
user = session.load(id_, Company)
user = session.load(id_, User)
user.name = f"Omer{i}"
session.save_changes()

Expand Down Expand Up @@ -392,7 +392,7 @@ def test_can_get_revisions_by_change_vectors_lazily(self):

for i in range(10):
with self.store.open_session() as session:
user = session.load(id_, Company)
user = session.load(id_, User)
user.name = f"Omer{i}"
session.save_changes()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import time
import unittest
from typing import Optional

from ravendb.documents.indexes.abstract_index_creation_tasks import AbstractIndexCreationTask
from ravendb.documents.session.loaders.include import QueryIncludeBuilder
from ravendb.documents.session.misc import TransactionMode, SessionOptions
from ravendb.documents.session.query import QueryStatistics
from ravendb.infrastructure.orders import Company, Address, Employee
from ravendb.tests.test_base import TestBase
from ravendb.util.util import StartingWithOptions


class Companies_ByName(AbstractIndexCreationTask):
Expand Down
51 changes: 0 additions & 51 deletions ravendb/tools/custom_decoder.py

This file was deleted.

61 changes: 0 additions & 61 deletions ravendb/tools/indexqueue.py

This file was deleted.

42 changes: 0 additions & 42 deletions ravendb/tools/projection.py

This file was deleted.

Loading

0 comments on commit 09b6a08

Please sign in to comment.