Skip to content

Commit 81d69c9

Browse files
committed
RDBC-179 Fix problematic code
- Fix Typos - Fix sending None values to server
1 parent 81305c3 commit 81d69c9

8 files changed

Lines changed: 47 additions & 19 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ with store.open_session() as session:
155155
##What`s new
156156
###Changes Api
157157
The RavenDB client offers a push notification feature that allows you to receive messages from a server about events that occurred there.
158-
ou are able to subscribe to events for all documents, indexes and operations as well as to indicate a particular
158+
You are able to subscribe to events for all documents, indexes and operations as well as to indicate a particular
159159
one that you are interested in. This mechanism lets you notify users if something has changed without
160160
the need to do any expensive polling.
161161

@@ -188,7 +188,7 @@ In this example we want to observe to changes from all documents and for index w
188188
After we register the observable we can subscribe for the notification and decide what to do with them (like append).
189189

190190
If you did not create an Observer for the subscription we will create one for you with the method you put.
191-
(To create Observer you can make any class that you want the will inherit from the class Observer
191+
(To create Observer you can make any class that you want that will inherit from the class Observer
192192
can be found in pyravendb.changes.observers or to use the ActionObserver).
193193

194194
```python
@@ -204,4 +204,7 @@ class Observer(metaclass=ABCMeta):
204204
@abstractmethod
205205
def on_next(self, value):
206206
pass
207-
```
207+
```
208+
209+
#####Bug Tracker
210+
http://issues.hibernatingrhinos.com/issues/RDBC

pyravendb/commands/commands_data.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def __init__(self, key, change_vector=None, document=None, metadata=None):
2626

2727
def to_json(self):
2828
self.document["@metadata"] = self.metadata
29-
return {"Type": self._type, "Id": self.key, "Document": self.document, "ChangeVector": self.change_vector}
29+
data = {"Type": self._type, "Id": self.key, "Document": self.document}
30+
if self.change_vector:
31+
data["ChangeVector"] = self.change_vector
32+
return data
3033

3134

3235
class DeleteCommandData(_CommandData):
@@ -35,7 +38,10 @@ def __init__(self, key, change_vector=None):
3538
self.additionalData = None
3639

3740
def to_json(self):
38-
return {"Id": self.key, "ChangeVector": self.change_vector, "Type": self._type}
41+
data = {"Id": self.key, "ChangeVector": self.change_vector, "Type": self._type}
42+
if self.change_vector:
43+
data["ChangeVector"] = self.change_vector
44+
return {"Id": self.key, "Type": self._type}
3945

4046

4147
class PatchCommandData(_CommandData):
@@ -67,10 +73,13 @@ def __init__(self, key, scripted_patch, change_vector=None, patch_if_missing=Non
6773
self.debug_Mode = debug_mode
6874

6975
def to_json(self):
70-
data = {"Id": self.key, "ChangeVector": self.change_vector, "Type": self._type,
76+
data = {"Id": self.key, "Type": self._type,
7177
"Patch": self.scripted_patch.to_json(),
7278
"DebugMode": self.debug_Mode}
7379

80+
if self.change_vector:
81+
data["ChangeVector"] = self.change_vector
82+
7483
if self.patch_if_missing is not None:
7584
data["PatchIfMissing"] = self.patch_if_missing.to_json()
7685

@@ -98,8 +107,12 @@ def __init__(self, document_id, name, stream, content_type, change_vector):
98107
self.content_type = content_type
99108

100109
def to_json(self):
101-
return {"Id": self.key, "Name": self.name, "ContentType": self.content_type,
102-
"ChangeVector": self.change_vector, "Type": self._type}
110+
data = {"Id": self.key, "Name": self.name, "ContentType": self.content_type, "Type": self._type}
111+
112+
if self.change_vector:
113+
data["ChangeVector"] = self.change_vector
114+
115+
return data
103116

104117

105118
class DeleteAttachmentCommandData(_CommandData):
@@ -119,5 +132,9 @@ def __init__(self, document_id, name, change_vector):
119132
self.name = name
120133

121134
def to_json(self):
122-
return {"Id": self.key, "Name": self.name,
123-
"ChangeVector": self.change_vector, "Type": self._type}
135+
data = {"Id": self.key, "Name": self.name, "Type": self._type}
136+
137+
if self.change_vector:
138+
data["ChangeVector"] = self.change_vector
139+
140+
return data

pyravendb/data/query.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from pyravendb.tools.utils import Utils
22
from abc import ABCMeta
3-
from datetime import timedelta
43
from enum import Enum
54
import json
65
import xxhash

pyravendb/hilo/hilo_generator.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ def generate_document_key(self, entity):
9393
tag = self._conventions.default_transform_type_tag_name(entity.__class__.__name__)
9494
if tag is None:
9595
return None
96-
if tag in self.key_generators_by_tag:
97-
value = self.key_generators_by_tag[tag]
9896
else:
9997
with self.lock:
10098
if tag in self.key_generators_by_tag:

pyravendb/store/document_session.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def _update_batch_result(self, batch_result, data):
328328
if entity in self._documents_by_entity:
329329
self._documents_by_id[item["@id"]] = entity
330330
document_info = self._documents_by_entity[entity]
331-
document_info["change_vector"] = ["change_vector"]
331+
document_info["change_vector"] = item["@change-vector"]
332332
item.pop("Type", None)
333333
document_info["original_metadata"] = item.copy()
334334
document_info["metadata"] = item
@@ -341,7 +341,6 @@ def _prepare_for_delete_commands(self, data):
341341
keys_to_delete.append(self._documents_by_entity[entity]["key"])
342342

343343
for key in keys_to_delete:
344-
existing_entity = None
345344
change_vector = None
346345
if key in self._documents_by_id:
347346
existing_entity = self._documents_by_id[key]
@@ -350,7 +349,7 @@ def _prepare_for_delete_commands(self, data):
350349
"@change-vector"] if self.advanced.use_optimistic_concurrency else None
351350
self._documents_by_entity.pop(existing_entity, None)
352351
self._documents_by_id.pop(key, None)
353-
data.entities.append(existing_entity)
352+
data.entities.append(existing_entity)
354353
data.commands.append(commands_data.DeleteCommandData(key, change_vector))
355354
self._deleted_entities.clear()
356355

pyravendb/store/document_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get_request_executor(self, db_name=None):
9696
def initialize(self):
9797
if not self._initialize:
9898
if self.urls is None or len(self.urls) == 0:
99-
raise ValueError("Document store URLs cannot be empty", "urks")
99+
raise ValueError("Document store URLs cannot be empty", "urls")
100100
if self.database is None:
101101
raise exceptions.InvalidOperationException("None database is not valid")
102102

pyravendb/tests/session_tests/test_delete.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
sys.path.append(os.path.abspath(__file__ + "/../"))
55

66
from pyravendb.tests.test_base import TestBase
7-
from pyravendb.store.document_store import DocumentStore
87
from pyravendb.custom_exceptions import exceptions
98
import unittest
109

@@ -56,6 +55,19 @@ def test_delete_after_change_success_with_save_session(self):
5655
session.save_changes()
5756
self.assertIsNone(session.load("products/107"))
5857

58+
def test_delete_with_entity(self):
59+
product = Product("Toys")
60+
with self.store.open_session() as session:
61+
session.store(product)
62+
session.save_changes()
63+
64+
with self.store.open_session() as session:
65+
product = session.load(product.Id)
66+
session.delete(product)
67+
session.save_changes()
68+
69+
self.assertIsNone(session.load(product.Id))
70+
5971

6072
if __name__ == "__main__":
6173
unittest.main()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name='pyravendb',
55
packages=find_packages(),
6-
version='4.0.4.2',
6+
version='4.0.4.3',
77
description='This is the official python client for RavenDB v4.0 document database',
88
author='Idan Haim Shalom',
99
author_email='haimdude@gmail.com',

0 commit comments

Comments
 (0)