diff --git a/pyravendb/store/session_query.py b/pyravendb/store/session_query.py index af714fb6..fbacfbe3 100644 --- a/pyravendb/store/session_query.py +++ b/pyravendb/store/session_query.py @@ -270,7 +270,7 @@ def where_not_none(self, field_name): if len(self.query_builder) > 0: self.query_builder += ' ' self.query_builder += '(' - self.where_equals(field_name, '*').and_also().add_not().where_equals(field_name, None) + self.where_equals(field_name, '*', escape_query_options=EscapeQueryOptions.RawQuery).and_also().add_not().where_equals(field_name, None) self.query_builder += ')' return self @@ -321,8 +321,7 @@ def boost(self, value): def _execute_query(self): self.session.increment_requests_count() conventions = self.session.conventions - start_time = time.time() - end_time = start_time + conventions.timeout + end_time = time.time() + conventions.timeout while True: response = self.session.database_commands. \ query(self.index_name, IndexQuery(self.query_builder, default_operator=self.using_default_operator, @@ -331,7 +330,7 @@ def _execute_query(self): wait_for_non_stale_results=self.wait_for_non_stale_results), includes=self.includes) if response["IsStale"] and self.wait_for_non_stale_results: - if start_time > end_time: + if time.time() > end_time: raise ErrorResponseException("The index is still stale after reached the timeout") time.sleep(0.1) continue diff --git a/pyravendb/tests/session_tests/test_query.py b/pyravendb/tests/session_tests/test_query.py index a680dac8..6b34e102 100644 --- a/pyravendb/tests/session_tests/test_query.py +++ b/pyravendb/tests/session_tests/test_query.py @@ -47,6 +47,12 @@ def setUpClass(cls): {"name": "withNesting", "product": {"name": "testing_order", "key": 4, "order": None}}, {"Raven-Entity-Name": "Companies"}) cls.db.put("specials/1", {"url": "https://ravendb.net/"}) + cls.db.put("specials/2", + {"url": "http://www.example.com/ebx/LinkResolverServlet?classofcontent=Standard&id=63935", + "date": "2017.03.05T00:00:00.000"}) + cls.db.put("specials/3", + {"wild_cards": "%~#+!$,;'*[]?*", + "date": "2017.03.05T00:00:01.000"}) cls.document_store = documentstore(cls.default_url, cls.default_database) cls.document_store.initialize() @@ -94,6 +100,21 @@ def test_query_with_special_characters(self): self.assertTrue(len(query_result) > 0) self.assertTrue(query_result[0].url == url) + def test_query_with_wild_cards_and_select(self): + with self.document_store.open_session() as session: + url = "http://www.example.com/ebx/LinkResolverServlet?classofcontent=Standard&id=63935" + query_result = list(session.query().where_equals("url", url).select("date")) + self.assertTrue(len(query_result) > 0) + self.assertIsNotNone(query_result[0].date) + self.assertFalse(hasattr(query_result[0], "url")) + + def test_query_with_only_wild_cards(self): + with self.document_store.open_session() as session: + wild_cards = "%~#+!$,;'*[]?*" + query_result = list(session.query().where_equals("wild_cards", wild_cards)) + self.assertTrue(len(query_result) > 0) + self.assertIsNotNone(query_result[0].wild_cards) + def test_query_success_with_where(self): with self.document_store.open_session() as session: query_results = list(session.query().where(name="test101", key=[4, 6, 90])) diff --git a/pyravendb/tools/utils.py b/pyravendb/tools/utils.py index 8ffc8b2e..be632de5 100644 --- a/pyravendb/tools/utils.py +++ b/pyravendb/tools/utils.py @@ -23,13 +23,12 @@ def empty_etag(): @staticmethod def quote_key(key): - reserved = '%:=&?~#+!$,;\'*[]' if key: # To be able to work on python 2.x and 3.x if sys.version_info.major > 2: - return urllib.parse.quote(key, safe=reserved) + return urllib.parse.quote(key) else: - return urllib.quote(key, safe=reserved) + return urllib.quote(key) else: return '' @@ -282,7 +281,7 @@ def timedelta_to_str(timedelta_obj): @staticmethod def escape(term, allow_wild_cards, make_phrase): - wild_cards = ['-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', ':', '\\'] + wild_cards = ['-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', ':', '\\', '?', '*'] if not term: return "\"\"" start = 0 @@ -301,7 +300,7 @@ def escape(term, allow_wild_cards, make_phrase): if ch in wild_cards: if i > start: - builder += term[start:i - start] + builder += term[start:i] builder += '\\{0}'.format(ch) start = i + 1 diff --git a/setup.py b/setup.py index 26f604de..7d0389eb 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='pyravendb', packages=find_packages(), - version='1.3.1.3', + version='3.5.3.3', description='This is the official python client for RavenDB document database', author='Idan Haim Shalom', author_email='haimdude@gmail.com',