From a1b5b8709c400df021f6a0700fb6e06af72fa89f Mon Sep 17 00:00:00 2001 From: Adam Levin Date: Tue, 14 Dec 2021 11:20:13 -0800 Subject: [PATCH 1/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32af1628..520f1d17 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ Pony is an advanced object-relational mapper. The most interesting feature of Po Here is an example query in Pony: - select(p for p in Product if p.name.startswith('A') and p.cost <= 1000) +```python +select(p for p in Product if p.name.startswith('A') and p.cost <= 1000) +``` Pony translates queries to SQL using a specific database dialect. Currently Pony works with SQLite, MySQL, PostgreSQL and Oracle databases. From 87bbe2a3133e54e0efbd71649bb7dc863feac0c2 Mon Sep 17 00:00:00 2001 From: thomas-workstation Date: Thu, 15 Jun 2023 14:57:39 +0200 Subject: [PATCH 2/5] implement retry_delay capability --- pony/orm/core.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pony/orm/core.py b/pony/orm/core.py index 845e672a..3ca1ea3e 100644 --- a/pony/orm/core.py +++ b/pony/orm/core.py @@ -4,7 +4,7 @@ import builtins, json, re, sys, types, datetime, logging, itertools, warnings, inspect, ast from operator import attrgetter, itemgetter from itertools import chain, starmap, repeat -from time import time +from time import time, sleep from decimal import Decimal from random import shuffle, randint, random from threading import Lock, RLock, current_thread, _MainThread @@ -407,14 +407,16 @@ def rollback(): select_re = re.compile(r'\s*select\b', re.IGNORECASE) class DBSessionContextManager(object): - __slots__ = 'retry', 'retry_exceptions', 'allowed_exceptions', \ + __slots__ = 'retry', 'retry_delay', 'retry_exceptions', 'allowed_exceptions', \ 'immediate', 'ddl', 'serializable', 'strict', 'optimistic', \ 'sql_debug', 'show_values' - def __init__(db_session, retry=0, immediate=False, ddl=False, serializable=False, strict=False, optimistic=True, + def __init__(db_session, retry:int=0, retry_delay:int=0, immediate:bool=False, ddl:bool=False, serializable:bool=False, strict:bool=False, optimistic:bool=True, retry_exceptions=(TransactionError,), allowed_exceptions=(), sql_debug=None, show_values=None): if retry != 0: if type(retry) is not int: throw(TypeError, "'retry' parameter of db_session must be of integer type. Got: %s" % type(retry)) + if type(retry_delay) is not int: throw(TypeError, + "'retry_delay' parameter of db_session must be of integer type. Got: %s" % type(retry)) if retry < 0: throw(TypeError, "'retry' parameter of db_session must not be negative. Got: %d" % retry) if ddl: throw(TypeError, "'ddl' and 'retry' parameters of db_session cannot be used together") @@ -424,6 +426,7 @@ def __init__(db_session, retry=0, immediate=False, ddl=False, serializable=False 'The same exception %s cannot be specified in both ' 'allowed and retry exception lists simultaneously' % e.__name__) db_session.retry = retry + db_session.retry = retry_delay db_session.ddl = ddl db_session.serializable = serializable db_session.immediate = immediate or ddl or serializable or not optimistic @@ -533,6 +536,7 @@ def new_func(func, *args, **kwargs): if not do_retry: raise rollback() + sleep(db_session.retry_delay) finally: db_session.__exit__(exc_type, exc, tb) reraise(exc_type, exc, tb) From 162e51b12ace36b849ee21b6c7c9c62154282a6d Mon Sep 17 00:00:00 2001 From: thomas-workstation Date: Thu, 15 Jun 2023 15:08:53 +0200 Subject: [PATCH 3/5] increment version to 0.7.17 --- pony/__init__.py | 2 +- pony/orm/core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pony/__init__.py b/pony/__init__.py index 0201f2aa..536130f1 100644 --- a/pony/__init__.py +++ b/pony/__init__.py @@ -3,7 +3,7 @@ import os, sys from os.path import dirname -__version__ = '0.7.16' +__version__ = '0.7.17' def detect_mode(): try: import google.appengine diff --git a/pony/orm/core.py b/pony/orm/core.py index 3ca1ea3e..613649e9 100644 --- a/pony/orm/core.py +++ b/pony/orm/core.py @@ -426,7 +426,7 @@ def __init__(db_session, retry:int=0, retry_delay:int=0, immediate:bool=False, d 'The same exception %s cannot be specified in both ' 'allowed and retry exception lists simultaneously' % e.__name__) db_session.retry = retry - db_session.retry = retry_delay + db_session.retry_delay = retry_delay db_session.ddl = ddl db_session.serializable = serializable db_session.immediate = immediate or ddl or serializable or not optimistic From e22ecdcbe27dd6a07e7c3c790aaeee25d630d3a9 Mon Sep 17 00:00:00 2001 From: thomas-workstation Date: Thu, 15 Jun 2023 15:18:15 +0200 Subject: [PATCH 4/5] Changelog --- CHANGELOG.md | 4 ++++ README.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a86604..90ca4118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# PonyORM release 0.7.17 (2023-06-15) + +* Introduce retry_delay into retry db_session + # PonyORM release 0.7.16 (2022-01-28) ## Bugfixes diff --git a/README.md b/README.md index bafb038e..2058d7b1 100644 --- a/README.md +++ b/README.md @@ -64,4 +64,4 @@ Meet the PonyORM team, chat with the community members, and get your questions a Join our newsletter at [ponyorm.org](https://ponyorm.org). Reach us on [Twitter](https://twitter.com/ponyorm). -Copyright (c) 2013-2022 Pony ORM. All rights reserved. info (at) ponyorm.org +Copyright (c) 2013-2023 Pony ORM. All rights reserved. info (at) ponyorm.org From 89f62707b908338a295fdd8e1c80f0092e29423a Mon Sep 17 00:00:00 2001 From: thomas-workstation Date: Fri, 16 Jun 2023 12:27:34 +0200 Subject: [PATCH 5/5] add retry has to be positive --- pony/orm/core.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pony/orm/core.py b/pony/orm/core.py index 613649e9..60514bfc 100644 --- a/pony/orm/core.py +++ b/pony/orm/core.py @@ -419,6 +419,8 @@ def __init__(db_session, retry:int=0, retry_delay:int=0, immediate:bool=False, d "'retry_delay' parameter of db_session must be of integer type. Got: %s" % type(retry)) if retry < 0: throw(TypeError, "'retry' parameter of db_session must not be negative. Got: %d" % retry) + if retry_delay < 0: throw(TypeError, + "'retry_delay' parameter of db_session must not be negative. Got: %d" % retry) if ddl: throw(TypeError, "'ddl' and 'retry' parameters of db_session cannot be used together") if not callable(allowed_exceptions) and not callable(retry_exceptions): for e in allowed_exceptions: