Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 4, 2024
1 parent e9889a3 commit ade58c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
23 changes: 17 additions & 6 deletions src/apscheduler/datastores/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class SQLAlchemyDataStore(BaseExternalDataStore):
validator=instance_of((str, URL, Engine, AsyncEngine))
)
schema: str | None = attrs.field(kw_only=True, default=None)
table_prefix: str | None = attrs.field(kw_only=True, default='')
table_prefix: str | None = attrs.field(kw_only=True, default="")

_engine: Engine | AsyncEngine = attrs.field(init=False)
_close_on_exit: bool = attrs.field(init=False, default=False)
Expand Down Expand Up @@ -186,14 +186,25 @@ def __attrs_post_init__(self) -> None:
)
self._supports_native_interval = self._engine.dialect.name == "postgresql"
self._metadata = self.get_table_definitions()
self._t_metadata = self._metadata.tables[prefix + self.table_prefix + "metadata"]
self._t_metadata = self._metadata.tables[
prefix + self.table_prefix + "metadata"
]
self._t_tasks = self._metadata.tables[prefix + self.table_prefix + "tasks"]
self._t_schedules = self._metadata.tables[prefix + self.table_prefix + "schedules"]
self._t_schedules = self._metadata.tables[
prefix + self.table_prefix + "schedules"
]
self._t_jobs = self._metadata.tables[prefix + self.table_prefix + "jobs"]
self._t_job_results = self._metadata.tables[prefix + self.table_prefix + "job_results"]
self._t_job_results = self._metadata.tables[
prefix + self.table_prefix + "job_results"
]

def __repr__(self) -> str:
return create_repr(self, url=repr(self._engine.url), schema=self.schema, table_prefix=self.table_prefix)
return create_repr(
self,
url=repr(self._engine.url),
schema=self.schema,
table_prefix=self.table_prefix,
)

def _retry(self) -> tenacity.AsyncRetrying:
def after_attempt(retry_state: tenacity.RetryCallState) -> None:
Expand Down Expand Up @@ -310,7 +321,7 @@ def get_table_definitions(self) -> MetaData:
Table(
self.table_prefix + "metadata",
metadata,
Column("schema_version", Integer, nullable=False)
Column("schema_version", Integer, nullable=False),
)
Table(
self.table_prefix + "tasks",
Expand Down
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ async def aiosqlite_store(tmp_path: Path) -> AsyncGenerator[DataStore, None]:

@pytest.fixture(
params=[
pytest.param('', id="default_prefix"),
pytest.param('aps_', id="aps_prefix"),
pytest.param("", id="default_prefix"),
pytest.param("aps_", id="aps_prefix"),
]
)
def table_prefix(request) -> str:
Expand Down Expand Up @@ -252,7 +252,9 @@ async def patched_wait_for(fut, timeout):
)
try:
if table_prefix:
yield SQLAlchemyDataStore(engine, table_prefix=table_prefix, start_from_scratch=True)
yield SQLAlchemyDataStore(
engine, table_prefix=table_prefix, start_from_scratch=True
)
else:
yield SQLAlchemyDataStore(engine, start_from_scratch=True)
assert "Current Checked out connections: 0" in engine.pool.status()
Expand Down

0 comments on commit ade58c9

Please sign in to comment.