libres 1.1.2__tar.gz → 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {libres-1.1.2 → libres-1.2.0}/HISTORY.rst +15 -0
- {libres-1.1.2/src/libres.egg-info → libres-1.2.0}/PKG-INFO +16 -1
- {libres-1.1.2 → libres-1.2.0}/pyproject.toml +49 -49
- {libres-1.1.2 → libres-1.2.0}/src/libres/__init__.py +2 -2
- {libres-1.1.2 → libres-1.2.0}/src/libres/context/core.py +3 -3
- libres-1.2.0/src/libres/db/__init__.py +7 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/allocation.py +3 -3
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/blocker.py +1 -1
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/reservation.py +1 -1
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/reserved_slot.py +3 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/scheduler.py +35 -50
- {libres-1.1.2 → libres-1.2.0/src/libres.egg-info}/PKG-INFO +16 -1
- {libres-1.1.2 → libres-1.2.0}/tests/test_allocation.py +2 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_scheduler.py +71 -0
- libres-1.1.2/src/libres/db/__init__.py +0 -7
- {libres-1.1.2 → libres-1.2.0}/LICENSE +0 -0
- {libres-1.1.2 → libres-1.2.0}/MANIFEST.in +0 -0
- {libres-1.1.2 → libres-1.2.0}/README.rst +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/Makefile +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/_static/custom.css +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/_static/favicon.ico +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/_static/logo.svg +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/api.rst +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/concepts.rst +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/conf.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/customizations.rst +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/faq.rst +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/index.rst +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/requirements.txt +0 -0
- {libres-1.1.2 → libres-1.2.0}/docs/under_the_hood.rst +0 -0
- {libres-1.1.2 → libres-1.2.0}/setup.cfg +0 -0
- {libres-1.1.2 → libres-1.2.0}/setup.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/.gitignore +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/context/__init__.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/context/exposure.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/context/registry.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/context/session.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/context/settings.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/__init__.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/base.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/other.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/timespan.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/timestamp.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/types/__init__.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/types/json_type.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/types/utcdatetime.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/models/types/uuid_type.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/db/queries.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/modules/__init__.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/modules/errors.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/modules/events.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/modules/rasterizer.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/modules/utils.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres/py.typed +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres.egg-info/SOURCES.txt +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres.egg-info/dependency_links.txt +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres.egg-info/requires.txt +0 -0
- {libres-1.1.2 → libres-1.2.0}/src/libres.egg-info/top_level.txt +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_registry.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_reservation.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_reserved_slot.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_scheduler_blockers.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_session.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_test.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_types.py +0 -0
- {libres-1.1.2 → libres-1.2.0}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
---------
|
|
3
3
|
|
|
4
|
+
1.2.0 (13.08.2026)
|
|
5
|
+
~~~~~~~~~~~~~~~~~~~
|
|
6
|
+
|
|
7
|
+
- Records the owning reservation/blocker id on each reserved slot
|
|
8
|
+
|
|
9
|
+
ReservedSlot gains a ``source_id`` column holding the id of its owning
|
|
10
|
+
reservation or blocker (see ``source_type``). A slot can now be attributed to
|
|
11
|
+
its exact object directly, instead of inferring it from the allocation and
|
|
12
|
+
time range. This fixes ``reserved_slots_by_reservation`` dropping the slot on
|
|
13
|
+
non-partly_available allocations (where the slot spans the whole allocation
|
|
14
|
+
and is wider than a narrower reservation), which left orphaned slots behind on
|
|
15
|
+
removal. Consumers must add the column and backfill it (see the onegov
|
|
16
|
+
``add_source_id_to_reserved_slots`` upgrade).
|
|
17
|
+
[Tschuppi81]
|
|
18
|
+
|
|
4
19
|
1.1.2 (16.06.2026)
|
|
5
20
|
~~~~~~~~~~~~~~~~~~~
|
|
6
21
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libres
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: A library to reserve things
|
|
5
5
|
Author-email: Denis Krienbühl <denis@href.ch>
|
|
6
6
|
Maintainer-email: Seantis GmbH <info@seantis.ch>
|
|
@@ -116,6 +116,21 @@ After this, create a new release on Github.
|
|
|
116
116
|
Changelog
|
|
117
117
|
---------
|
|
118
118
|
|
|
119
|
+
1.2.0 (13.08.2026)
|
|
120
|
+
~~~~~~~~~~~~~~~~~~~
|
|
121
|
+
|
|
122
|
+
- Records the owning reservation/blocker id on each reserved slot
|
|
123
|
+
|
|
124
|
+
ReservedSlot gains a ``source_id`` column holding the id of its owning
|
|
125
|
+
reservation or blocker (see ``source_type``). A slot can now be attributed to
|
|
126
|
+
its exact object directly, instead of inferring it from the allocation and
|
|
127
|
+
time range. This fixes ``reserved_slots_by_reservation`` dropping the slot on
|
|
128
|
+
non-partly_available allocations (where the slot spans the whole allocation
|
|
129
|
+
and is wider than a narrower reservation), which left orphaned slots behind on
|
|
130
|
+
removal. Consumers must add the column and backfill it (see the onegov
|
|
131
|
+
``add_source_id_to_reserved_slots`` upgrade).
|
|
132
|
+
[Tschuppi81]
|
|
133
|
+
|
|
119
134
|
1.1.2 (16.06.2026)
|
|
120
135
|
~~~~~~~~~~~~~~~~~~~
|
|
121
136
|
|
|
@@ -100,7 +100,7 @@ branch = true
|
|
|
100
100
|
source = ["src"]
|
|
101
101
|
|
|
102
102
|
[tool.bumpversion]
|
|
103
|
-
current_version = "1.
|
|
103
|
+
current_version = "1.2.0"
|
|
104
104
|
commit = true
|
|
105
105
|
message = "Release {new_version}"
|
|
106
106
|
tag = true
|
|
@@ -197,21 +197,14 @@ target-version = "py310"
|
|
|
197
197
|
[tool.ruff.lint]
|
|
198
198
|
select = [
|
|
199
199
|
"B0",
|
|
200
|
-
"B904",
|
|
201
|
-
"B909",
|
|
202
200
|
"C4",
|
|
203
|
-
"COM818",
|
|
204
201
|
"D2",
|
|
205
|
-
"D301",
|
|
206
202
|
"D4",
|
|
207
203
|
"E",
|
|
208
204
|
"F",
|
|
209
|
-
"FLY002",
|
|
210
|
-
"I002",
|
|
211
205
|
"ISC",
|
|
212
206
|
"N",
|
|
213
207
|
"PERF",
|
|
214
|
-
"PGH004",
|
|
215
208
|
"PIE",
|
|
216
209
|
"PT",
|
|
217
210
|
"PYI",
|
|
@@ -220,48 +213,55 @@ select = [
|
|
|
220
213
|
"SIM",
|
|
221
214
|
"SLOT",
|
|
222
215
|
"UP",
|
|
223
|
-
"W"
|
|
216
|
+
"W",
|
|
217
|
+
"blanket-noqa",
|
|
218
|
+
"escape-sequence-in-docstring",
|
|
219
|
+
"loop-iterator-mutation",
|
|
220
|
+
"missing-required-import",
|
|
221
|
+
"raise-without-from-inside-except",
|
|
222
|
+
"static-join-to-f-string",
|
|
223
|
+
"trailing-comma-on-bare-tuple",
|
|
224
224
|
]
|
|
225
225
|
ignore = [
|
|
226
|
-
"
|
|
227
|
-
"
|
|
228
|
-
"
|
|
229
|
-
"
|
|
230
|
-
"
|
|
231
|
-
"
|
|
232
|
-
"
|
|
233
|
-
"
|
|
234
|
-
"
|
|
235
|
-
"
|
|
236
|
-
"
|
|
237
|
-
"
|
|
238
|
-
"
|
|
239
|
-
"
|
|
240
|
-
"
|
|
241
|
-
"
|
|
242
|
-
"
|
|
243
|
-
"
|
|
244
|
-
"
|
|
245
|
-
"
|
|
246
|
-
"
|
|
247
|
-
"
|
|
248
|
-
"
|
|
249
|
-
"
|
|
250
|
-
"
|
|
251
|
-
"
|
|
252
|
-
"
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
"
|
|
257
|
-
"
|
|
258
|
-
"
|
|
259
|
-
"
|
|
260
|
-
"
|
|
261
|
-
"
|
|
262
|
-
"
|
|
263
|
-
"
|
|
264
|
-
"
|
|
226
|
+
"ambiguous-variable-name",
|
|
227
|
+
"blank-line-after-function",
|
|
228
|
+
"blank-line-before-class",
|
|
229
|
+
"blank-line-before-function",
|
|
230
|
+
"blank-lines-between-header-and-content",
|
|
231
|
+
"custom-type-var-for-self",
|
|
232
|
+
"dict-get-with-none-default",
|
|
233
|
+
"error-suffix-on-exception-name",
|
|
234
|
+
"f-string",
|
|
235
|
+
"falsy-dict-get-fallback",
|
|
236
|
+
"if-else-block-instead-of-if-exp",
|
|
237
|
+
"if-expr-with-true-false",
|
|
238
|
+
"implicit-optional",
|
|
239
|
+
"in-dict-keys",
|
|
240
|
+
"incorrect-blank-line-after-class",
|
|
241
|
+
"incorrectly-parenthesized-tuple-in-subscript",
|
|
242
|
+
"missing-blank-line-after-summary",
|
|
243
|
+
"missing-trailing-period",
|
|
244
|
+
"missing-whitespace-around-arithmetic-operator",
|
|
245
|
+
"module-import-not-at-top-of-file",
|
|
246
|
+
"mutable-class-default",
|
|
247
|
+
"needless-bool",
|
|
248
|
+
"new-line-after-last-paragraph",
|
|
249
|
+
"non-imperative-mood",
|
|
250
|
+
"none-comparison",
|
|
251
|
+
"parenthesize-chained-operators",
|
|
252
|
+
"reimplemented-builtin",
|
|
253
|
+
"redundant-numeric-union",
|
|
254
|
+
"suppressible-exception",
|
|
255
|
+
"surrounding-whitespace",
|
|
256
|
+
"true-false-comparison",
|
|
257
|
+
"unnecessary-dict-comprehension-for-iterable",
|
|
258
|
+
"unnecessary-encode-utf8",
|
|
259
|
+
"unnecessary-multiline-docstring",
|
|
260
|
+
"unsorted-dunder-all",
|
|
261
|
+
"unsorted-dunder-slots",
|
|
262
|
+
"unused-loop-control-variable",
|
|
263
|
+
"used-dummy-variable",
|
|
264
|
+
"utf8-encoding-declaration",
|
|
265
265
|
]
|
|
266
266
|
unfixable = []
|
|
267
267
|
external = ["TC"]
|
|
@@ -273,7 +273,6 @@ preview = true
|
|
|
273
273
|
"tests/**/*.py" = [
|
|
274
274
|
"C4",
|
|
275
275
|
"D",
|
|
276
|
-
"FLY002",
|
|
277
276
|
"ISC",
|
|
278
277
|
"N",
|
|
279
278
|
"Q",
|
|
@@ -284,6 +283,7 @@ preview = true
|
|
|
284
283
|
"RUF",
|
|
285
284
|
"SIM",
|
|
286
285
|
"UP",
|
|
286
|
+
"static-join-to-f-string",
|
|
287
287
|
]
|
|
288
288
|
|
|
289
289
|
[tool.ruff.lint.isort]
|
|
@@ -3,9 +3,9 @@ from __future__ import annotations
|
|
|
3
3
|
from libres.context.registry import create_default_registry
|
|
4
4
|
from libres.db import new_scheduler
|
|
5
5
|
|
|
6
|
-
registry = create_default_registry() #
|
|
6
|
+
registry = create_default_registry() # ruff: ignore[non-empty-init-module]
|
|
7
7
|
|
|
8
|
-
__version__ = '1.
|
|
8
|
+
__version__ = '1.2.0'
|
|
9
9
|
__all__ = (
|
|
10
10
|
'new_scheduler',
|
|
11
11
|
'registry'
|
|
@@ -30,8 +30,8 @@ class _Marker(enum.Enum):
|
|
|
30
30
|
required = enum.auto()
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
missing_t: TypeAlias = Literal[_Marker.missing] #
|
|
34
|
-
required_t: TypeAlias = Literal[_Marker.required] #
|
|
33
|
+
missing_t: TypeAlias = Literal[_Marker.missing] # ruff: ignore[snake-case-type-alias]
|
|
34
|
+
required_t: TypeAlias = Literal[_Marker.required] # ruff: ignore[snake-case-type-alias]
|
|
35
35
|
missing: missing_t = _Marker.missing
|
|
36
36
|
required: required_t = _Marker.required
|
|
37
37
|
|
|
@@ -95,7 +95,7 @@ class ContextServicesMixin:
|
|
|
95
95
|
|
|
96
96
|
@property
|
|
97
97
|
def session(self) -> Session:
|
|
98
|
-
"""
|
|
98
|
+
""" The current session. """
|
|
99
99
|
return self.session_provider.session() # type: ignore[no-any-return]
|
|
100
100
|
|
|
101
101
|
def close(self) -> None:
|
|
@@ -502,7 +502,7 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
|
|
|
502
502
|
|
|
503
503
|
@property
|
|
504
504
|
def pending_reservations(self) -> Query[_ReservationIdRow]:
|
|
505
|
-
"""
|
|
505
|
+
""" The pending reservations query for this allocation.
|
|
506
506
|
As the pending reservations target the group and not a specific
|
|
507
507
|
allocation this function returns the same value for masters and
|
|
508
508
|
mirrors.
|
|
@@ -517,7 +517,7 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
|
|
|
517
517
|
"Don't call if the allocation is detached"
|
|
518
518
|
)
|
|
519
519
|
|
|
520
|
-
Reservation = self.models.Reservation #
|
|
520
|
+
Reservation = self.models.Reservation # ruff: ignore[non-lowercase-variable-in-function]
|
|
521
521
|
query: Query[_ReservationIdRow]
|
|
522
522
|
query = session.query(Reservation.id) # type: ignore[assignment]
|
|
523
523
|
query = query.filter(Reservation.target == self.group)
|
|
@@ -531,7 +531,7 @@ class Allocation(TimestampMixin, ORMBase, OtherModels):
|
|
|
531
531
|
|
|
532
532
|
@property
|
|
533
533
|
def availability(self) -> float:
|
|
534
|
-
"""
|
|
534
|
+
"""The availability in percent."""
|
|
535
535
|
|
|
536
536
|
total = self.count_slots()
|
|
537
537
|
blocked = sum(
|
|
@@ -84,7 +84,7 @@ class ReservationBlocker(TimestampMixin, ORMBase, OtherModels):
|
|
|
84
84
|
assert session, (
|
|
85
85
|
"Don't call if the blocker is detached"
|
|
86
86
|
)
|
|
87
|
-
Allocation = self.models.Allocation #
|
|
87
|
+
Allocation = self.models.Allocation # ruff: ignore[non-lowercase-variable-in-function]
|
|
88
88
|
query = session.query(Allocation)
|
|
89
89
|
query = query.filter(Allocation.group == self.target)
|
|
90
90
|
|
|
@@ -107,7 +107,7 @@ class Reservation(TimestampMixin, ORMBase, OtherModels):
|
|
|
107
107
|
assert session, (
|
|
108
108
|
"Don't call if the reservation is detached"
|
|
109
109
|
)
|
|
110
|
-
Allocation = self.models.Allocation #
|
|
110
|
+
Allocation = self.models.Allocation # ruff: ignore[non-lowercase-variable-in-function]
|
|
111
111
|
query = session.query(Allocation)
|
|
112
112
|
query = query.filter(Allocation.group == self.target)
|
|
113
113
|
|
|
@@ -68,6 +68,9 @@ class ReservedSlot(TimestampMixin, ORMBase):
|
|
|
68
68
|
|
|
69
69
|
reservation_token: Mapped[UUID]
|
|
70
70
|
|
|
71
|
+
# id of the owning Reservation or ReservationBlocker (see source_type)
|
|
72
|
+
source_id: Mapped[int] = mapped_column(index=True)
|
|
73
|
+
|
|
71
74
|
__table_args__ = (
|
|
72
75
|
Index('reservation_resource_ix', 'reservation_token', 'resource'),
|
|
73
76
|
# NOTE: GiST index for temporal queries on reserved slots
|
|
@@ -9,7 +9,7 @@ from operator import attrgetter
|
|
|
9
9
|
from sqlalchemy import exc
|
|
10
10
|
from sqlalchemy import func
|
|
11
11
|
from sqlalchemy.orm import selectinload
|
|
12
|
-
from sqlalchemy.sql import and_, not_
|
|
12
|
+
from sqlalchemy.sql import and_, not_
|
|
13
13
|
from uuid import uuid4 as new_uuid, UUID
|
|
14
14
|
|
|
15
15
|
from libres.context.core import ContextServicesMixin
|
|
@@ -41,7 +41,7 @@ if TYPE_CHECKING:
|
|
|
41
41
|
from libres.context.core import Context
|
|
42
42
|
from libres.modules.rasterizer import Raster
|
|
43
43
|
|
|
44
|
-
_dtrange: TypeAlias = tuple[datetime, datetime] #
|
|
44
|
+
_dtrange: TypeAlias = tuple[datetime, datetime] # ruff: ignore[snake-case-type-alias]
|
|
45
45
|
|
|
46
46
|
class _ReserveArgs1(TypedDict):
|
|
47
47
|
email: str
|
|
@@ -1491,6 +1491,7 @@ class Scheduler(ContextServicesMixin):
|
|
|
1491
1491
|
slot.resource = allocation.resource
|
|
1492
1492
|
slot.reservation_token = reservation.token
|
|
1493
1493
|
slot.source_type = 'reservation'
|
|
1494
|
+
slot.source_id = reservation.id
|
|
1494
1495
|
|
|
1495
1496
|
# the slots are written with the allocation
|
|
1496
1497
|
allocation.reserved_slots.append(slot)
|
|
@@ -1671,7 +1672,7 @@ class Scheduler(ContextServicesMixin):
|
|
|
1671
1672
|
existing_reservation = self.reservations_by_token(token, id).one()
|
|
1672
1673
|
|
|
1673
1674
|
# if there's nothing to change, do not change
|
|
1674
|
-
if quota is None or existing_reservation.quota == quota: #
|
|
1675
|
+
if quota is None or existing_reservation.quota == quota: # ruff: ignore[collapsible-if]
|
|
1675
1676
|
if existing_reservation.start == new_start:
|
|
1676
1677
|
ends = (new_end, new_end - timedelta(microseconds=1))
|
|
1677
1678
|
|
|
@@ -1729,7 +1730,8 @@ class Scheduler(ContextServicesMixin):
|
|
|
1729
1730
|
dates: _dtrange | Collection[_dtrange],
|
|
1730
1731
|
group: None = ...,
|
|
1731
1732
|
reason: str | None = ...,
|
|
1732
|
-
token: UUID | None =
|
|
1733
|
+
token: UUID | None = ...,
|
|
1734
|
+
id: int | None = ...
|
|
1733
1735
|
) -> list[ReservationBlocker]: ...
|
|
1734
1736
|
|
|
1735
1737
|
@overload
|
|
@@ -1738,7 +1740,8 @@ class Scheduler(ContextServicesMixin):
|
|
|
1738
1740
|
dates: None,
|
|
1739
1741
|
group: UUID,
|
|
1740
1742
|
reason: str | None = ...,
|
|
1741
|
-
token: UUID | None =
|
|
1743
|
+
token: UUID | None = ...,
|
|
1744
|
+
id: int | None = ...
|
|
1742
1745
|
) -> list[ReservationBlocker]: ...
|
|
1743
1746
|
|
|
1744
1747
|
@overload
|
|
@@ -1748,7 +1751,8 @@ class Scheduler(ContextServicesMixin):
|
|
|
1748
1751
|
*,
|
|
1749
1752
|
group: UUID,
|
|
1750
1753
|
reason: str | None = ...,
|
|
1751
|
-
token: UUID | None =
|
|
1754
|
+
token: UUID | None = ...,
|
|
1755
|
+
id: int | None = ...
|
|
1752
1756
|
) -> list[ReservationBlocker]: ...
|
|
1753
1757
|
|
|
1754
1758
|
def add_blocker(
|
|
@@ -1756,7 +1760,8 @@ class Scheduler(ContextServicesMixin):
|
|
|
1756
1760
|
dates: _dtrange | Collection[_dtrange] | None = None,
|
|
1757
1761
|
group: UUID | None = None,
|
|
1758
1762
|
reason: str | None = None,
|
|
1759
|
-
token: UUID | None = None
|
|
1763
|
+
token: UUID | None = None,
|
|
1764
|
+
id: int | None = None
|
|
1760
1765
|
) -> list[ReservationBlocker]:
|
|
1761
1766
|
""" Adds a blocker to one or many allocations.
|
|
1762
1767
|
|
|
@@ -1827,7 +1832,6 @@ class Scheduler(ContextServicesMixin):
|
|
|
1827
1832
|
elif not allocation.contains(start, end):
|
|
1828
1833
|
raise errors.TimerangeTooLong
|
|
1829
1834
|
|
|
1830
|
-
# ok, we're good to go
|
|
1831
1835
|
if token is None:
|
|
1832
1836
|
token = new_uuid()
|
|
1833
1837
|
reserved_slots = []
|
|
@@ -1836,6 +1840,7 @@ class Scheduler(ContextServicesMixin):
|
|
|
1836
1840
|
allocation: Allocation,
|
|
1837
1841
|
start: datetime,
|
|
1838
1842
|
end: datetime,
|
|
1843
|
+
source_id: int,
|
|
1839
1844
|
including_mirrors: bool = True
|
|
1840
1845
|
) -> None:
|
|
1841
1846
|
for slot_start, slot_end in allocation.all_slots(start, end):
|
|
@@ -1845,6 +1850,7 @@ class Scheduler(ContextServicesMixin):
|
|
|
1845
1850
|
slot.resource = allocation.resource
|
|
1846
1851
|
slot.reservation_token = token
|
|
1847
1852
|
slot.source_type = 'blocker'
|
|
1853
|
+
slot.source_id = source_id
|
|
1848
1854
|
|
|
1849
1855
|
# the slots are written with the allocation
|
|
1850
1856
|
allocation.reserved_slots.append(slot)
|
|
@@ -1859,7 +1865,7 @@ class Scheduler(ContextServicesMixin):
|
|
|
1859
1865
|
|
|
1860
1866
|
for mirror in self.allocation_mirrors_by_master(allocation):
|
|
1861
1867
|
create_reserved_slots(
|
|
1862
|
-
mirror, start, end,
|
|
1868
|
+
mirror, start, end, source_id,
|
|
1863
1869
|
including_mirrors=False
|
|
1864
1870
|
)
|
|
1865
1871
|
|
|
@@ -1877,12 +1883,18 @@ class Scheduler(ContextServicesMixin):
|
|
|
1877
1883
|
blocker.target_type = 'group'
|
|
1878
1884
|
blocker.resource = self.resource
|
|
1879
1885
|
blocker.reason = reason
|
|
1886
|
+
if id is not None:
|
|
1887
|
+
blocker.id = id
|
|
1880
1888
|
|
|
1889
|
+
# flush to assign the blocker id before its slots reference it
|
|
1890
|
+
self.session.add(blocker)
|
|
1891
|
+
self.session.flush()
|
|
1881
1892
|
for allocation in self.allocations_by_group(group):
|
|
1882
1893
|
create_reserved_slots(
|
|
1883
1894
|
allocation,
|
|
1884
1895
|
allocation._start,
|
|
1885
|
-
allocation._end
|
|
1896
|
+
allocation._end,
|
|
1897
|
+
blocker.id
|
|
1886
1898
|
)
|
|
1887
1899
|
|
|
1888
1900
|
yield blocker
|
|
@@ -1919,8 +1931,15 @@ class Scheduler(ContextServicesMixin):
|
|
|
1919
1931
|
blocker.target_type = 'allocation'
|
|
1920
1932
|
blocker.resource = self.resource
|
|
1921
1933
|
blocker.reason = reason
|
|
1922
|
-
|
|
1923
|
-
|
|
1934
|
+
if id is not None:
|
|
1935
|
+
blocker.id = id
|
|
1936
|
+
|
|
1937
|
+
# flush to assign the id before its slots reference it
|
|
1938
|
+
self.session.add(blocker)
|
|
1939
|
+
self.session.flush()
|
|
1940
|
+
create_reserved_slots(
|
|
1941
|
+
allocation, start, end, blocker.id
|
|
1942
|
+
)
|
|
1924
1943
|
|
|
1925
1944
|
yield blocker
|
|
1926
1945
|
|
|
@@ -1936,9 +1955,6 @@ class Scheduler(ContextServicesMixin):
|
|
|
1936
1955
|
if not reserved_slots:
|
|
1937
1956
|
raise errors.NotReservableError
|
|
1938
1957
|
|
|
1939
|
-
for blocker in blockers:
|
|
1940
|
-
self.session.add(blocker)
|
|
1941
|
-
|
|
1942
1958
|
return blockers
|
|
1943
1959
|
|
|
1944
1960
|
def remove_blocker(
|
|
@@ -2018,9 +2034,9 @@ class Scheduler(ContextServicesMixin):
|
|
|
2018
2034
|
new_blocker, = self.add_blocker(
|
|
2019
2035
|
dates=(new_start, new_end),
|
|
2020
2036
|
reason=old_reason,
|
|
2021
|
-
token=token
|
|
2037
|
+
token=token,
|
|
2038
|
+
id=id
|
|
2022
2039
|
)
|
|
2023
|
-
new_blocker.id = id
|
|
2024
2040
|
|
|
2025
2041
|
return new_blocker
|
|
2026
2042
|
|
|
@@ -2297,24 +2313,7 @@ class Scheduler(ContextServicesMixin):
|
|
|
2297
2313
|
if id is None:
|
|
2298
2314
|
return query
|
|
2299
2315
|
|
|
2300
|
-
|
|
2301
|
-
# on a partly_available allocation; filter by time range instead.
|
|
2302
|
-
# start is None for group reservations — the or_ includes all their
|
|
2303
|
-
# slots.
|
|
2304
|
-
return (
|
|
2305
|
-
query
|
|
2306
|
-
.join(Reservation, and_(
|
|
2307
|
-
Reservation.token == ReservedSlot.reservation_token,
|
|
2308
|
-
Reservation.id == id
|
|
2309
|
-
))
|
|
2310
|
-
.filter(or_(
|
|
2311
|
-
Reservation.start.is_(None),
|
|
2312
|
-
and_(
|
|
2313
|
-
ReservedSlot.start >= Reservation.start,
|
|
2314
|
-
ReservedSlot.end <= Reservation.end,
|
|
2315
|
-
)
|
|
2316
|
-
))
|
|
2317
|
-
)
|
|
2316
|
+
return query.filter(ReservedSlot.source_id == id)
|
|
2318
2317
|
|
|
2319
2318
|
def reserved_slots_by_blocker(
|
|
2320
2319
|
self,
|
|
@@ -2331,21 +2330,7 @@ class Scheduler(ContextServicesMixin):
|
|
|
2331
2330
|
if id is None:
|
|
2332
2331
|
return query
|
|
2333
2332
|
|
|
2334
|
-
|
|
2335
|
-
return (
|
|
2336
|
-
query
|
|
2337
|
-
.join(ReservationBlocker, and_(
|
|
2338
|
-
ReservationBlocker.token == ReservedSlot.reservation_token,
|
|
2339
|
-
ReservationBlocker.id == id
|
|
2340
|
-
))
|
|
2341
|
-
.filter(or_(
|
|
2342
|
-
ReservationBlocker.start.is_(None),
|
|
2343
|
-
and_(
|
|
2344
|
-
ReservedSlot.start >= ReservationBlocker.start,
|
|
2345
|
-
ReservedSlot.end <= ReservationBlocker.end,
|
|
2346
|
-
)
|
|
2347
|
-
))
|
|
2348
|
-
)
|
|
2333
|
+
return query.filter(ReservedSlot.source_id == id)
|
|
2349
2334
|
|
|
2350
2335
|
def reservations_by_group(self, group: UUID) -> Query[Reservation]:
|
|
2351
2336
|
tokens = self.managed_reservations().with_entities(Reservation.token)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libres
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: A library to reserve things
|
|
5
5
|
Author-email: Denis Krienbühl <denis@href.ch>
|
|
6
6
|
Maintainer-email: Seantis GmbH <info@seantis.ch>
|
|
@@ -116,6 +116,21 @@ After this, create a new release on Github.
|
|
|
116
116
|
Changelog
|
|
117
117
|
---------
|
|
118
118
|
|
|
119
|
+
1.2.0 (13.08.2026)
|
|
120
|
+
~~~~~~~~~~~~~~~~~~~
|
|
121
|
+
|
|
122
|
+
- Records the owning reservation/blocker id on each reserved slot
|
|
123
|
+
|
|
124
|
+
ReservedSlot gains a ``source_id`` column holding the id of its owning
|
|
125
|
+
reservation or blocker (see ``source_type``). A slot can now be attributed to
|
|
126
|
+
its exact object directly, instead of inferring it from the allocation and
|
|
127
|
+
time range. This fixes ``reserved_slots_by_reservation`` dropping the slot on
|
|
128
|
+
non-partly_available allocations (where the slot spans the whole allocation
|
|
129
|
+
and is wider than a narrower reservation), which left orphaned slots behind on
|
|
130
|
+
removal. Consumers must add the column and backfill it (see the onegov
|
|
131
|
+
``add_source_id_to_reserved_slots`` upgrade).
|
|
132
|
+
[Tschuppi81]
|
|
133
|
+
|
|
119
134
|
1.1.2 (16.06.2026)
|
|
120
135
|
~~~~~~~~~~~~~~~~~~~
|
|
121
136
|
|
|
@@ -255,6 +255,7 @@ def add_reservation(
|
|
|
255
255
|
slot.allocation = allocation
|
|
256
256
|
slot.reservation_token = reservation
|
|
257
257
|
slot.source_type = 'reservation'
|
|
258
|
+
slot.source_id = 1 # synthetic slot, no real owner
|
|
258
259
|
scheduler.session.add(slot)
|
|
259
260
|
scheduler.session.flush()
|
|
260
261
|
scheduler.session.refresh(allocation)
|
|
@@ -281,6 +282,7 @@ def add_blocker(
|
|
|
281
282
|
slot.allocation = allocation
|
|
282
283
|
slot.reservation_token = blocker
|
|
283
284
|
slot.source_type = 'blocker'
|
|
285
|
+
slot.source_id = 1 # synthetic slot, no real owner
|
|
284
286
|
scheduler.session.add(slot)
|
|
285
287
|
scheduler.session.flush()
|
|
286
288
|
scheduler.session.refresh(allocation)
|
|
@@ -691,6 +691,77 @@ def test_remove_reservation_does_not_affect_sibling_reservations(
|
|
|
691
691
|
assert remaining_count == slots_a_count
|
|
692
692
|
|
|
693
693
|
|
|
694
|
+
def test_remove_reservation_on_non_partly_allocation_removes_slot(
|
|
695
|
+
scheduler: Scheduler,
|
|
696
|
+
) -> None:
|
|
697
|
+
"""On a non-partly allocation the reserved slot spans the whole
|
|
698
|
+
allocation, even if the reservation was made for a narrower (but
|
|
699
|
+
contained) range. Matching slots by time range would then drop the slot,
|
|
700
|
+
leaving an orphaned ReservedSlot behind that keeps showing up on the
|
|
701
|
+
calendar after the reservation was removed (OGC-3388)."""
|
|
702
|
+
dates = (datetime(2014, 3, 7, 8, 0), datetime(2014, 3, 7, 18, 0))
|
|
703
|
+
scheduler.allocate(dates, partly_available=False)
|
|
704
|
+
|
|
705
|
+
# a contained sub-range is accepted on a whole-only allocation, but the
|
|
706
|
+
# slot still covers the entire allocation
|
|
707
|
+
sub = (datetime(2014, 3, 7, 9, 0), datetime(2014, 3, 7, 17, 0))
|
|
708
|
+
token = scheduler.reserve('user@example.org', sub)
|
|
709
|
+
scheduler.commit()
|
|
710
|
+
scheduler.approve_reservations(token)
|
|
711
|
+
scheduler.commit()
|
|
712
|
+
|
|
713
|
+
reservation = scheduler.reservations_by_token(token).one()
|
|
714
|
+
assert reservation.start is not None
|
|
715
|
+
assert reservation.end is not None
|
|
716
|
+
slot = scheduler.reserved_slots_by_reservation(token).one()
|
|
717
|
+
# the slot is wider than the reservation range
|
|
718
|
+
assert slot.start < reservation.start or slot.end > reservation.end
|
|
719
|
+
|
|
720
|
+
# the slot must still be attributed to this reservation ...
|
|
721
|
+
assert scheduler.reserved_slots_by_reservation(
|
|
722
|
+
token, reservation.id
|
|
723
|
+
).count() == 1
|
|
724
|
+
|
|
725
|
+
# ... and removing the reservation must not leave an orphaned slot
|
|
726
|
+
scheduler.remove_reservation(token, reservation.id)
|
|
727
|
+
scheduler.commit()
|
|
728
|
+
assert scheduler.reserved_slots_by_type(token, 'reservation').count() == 0
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
def test_reserved_slots_store_source_id(scheduler: Scheduler) -> None:
|
|
732
|
+
"""Every reserved slot records the id of its owning reservation/blocker
|
|
733
|
+
(source_id), so it can be attributed to its exact object directly."""
|
|
734
|
+
dates = (datetime(2014, 3, 7, 8, 0), datetime(2014, 3, 7, 18, 0))
|
|
735
|
+
scheduler.allocate(dates, partly_available=True)
|
|
736
|
+
|
|
737
|
+
token = scheduler.reserve(
|
|
738
|
+
'user@example.org',
|
|
739
|
+
(datetime(2014, 3, 7, 8, 0), datetime(2014, 3, 7, 10, 0))
|
|
740
|
+
)
|
|
741
|
+
scheduler.commit()
|
|
742
|
+
scheduler.approve_reservations(token)
|
|
743
|
+
scheduler.commit()
|
|
744
|
+
|
|
745
|
+
reservation = scheduler.reservations_by_token(token).one()
|
|
746
|
+
slots = scheduler.reserved_slots_by_reservation(token).all()
|
|
747
|
+
assert slots
|
|
748
|
+
for slot in slots:
|
|
749
|
+
assert slot.source_type == 'reservation'
|
|
750
|
+
assert slot.source_id == reservation.id
|
|
751
|
+
|
|
752
|
+
blocker = scheduler.add_blocker(
|
|
753
|
+
(datetime(2014, 3, 7, 10, 0), datetime(2014, 3, 7, 12, 0))
|
|
754
|
+
)[0]
|
|
755
|
+
assert blocker.id is not None
|
|
756
|
+
scheduler.commit()
|
|
757
|
+
|
|
758
|
+
blocker_slots = scheduler.reserved_slots_by_blocker(blocker.token).all()
|
|
759
|
+
assert blocker_slots
|
|
760
|
+
for slot in blocker_slots:
|
|
761
|
+
assert slot.source_type == 'blocker'
|
|
762
|
+
assert slot.source_id == blocker.id
|
|
763
|
+
|
|
764
|
+
|
|
694
765
|
def test_remove_blocker_does_not_affect_sibling_blockers(
|
|
695
766
|
scheduler: Scheduler,
|
|
696
767
|
) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|