Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FTM cross-compatible with SQLAlchemy 1.4 and 2+ #1181

Merged
merged 7 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions followthemoney/mapping/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ def __init__(self, query: "QueryMapping", data: Dict[str, Any]) -> None:
if database is None:
raise InvalidMapping("No database in SQL mapping!")
self.database_uri = cast(str, os.path.expandvars(database))
kwargs = {}
if self.database_uri.lower().startswith("postgres"):
kwargs["server_side_cursors"] = True
self.engine = create_engine(self.database_uri, poolclass=NullPool, **kwargs) # type: ignore
self.engine = create_engine(self.database_uri, poolclass=NullPool)
self.meta = MetaData()

tables = keys_values(data, "table", "tables")
Expand Down Expand Up @@ -104,7 +101,7 @@ def records(self) -> Generator[Record, None, None]:
q = self.compose_query()
log.info("Query: %s", q)
with self.engine.connect() as conn:
rp = conn.execute(q)
rp = conn.execution_options(stream_results=True).execute(q)
while True:
rows = rp.fetchmany(size=DATA_PAGE)
if not len(rows):
Expand All @@ -124,4 +121,4 @@ def __len__(self) -> int:
q = self.apply_filters(q)
with self.engine.connect() as conn:
rp = conn.execute(q)
return int(rp.scalar())
return int(rp.scalar() or 0)
6 changes: 3 additions & 3 deletions setup.py
Copy link
Contributor

@tillprochaska tillprochaska Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason why the version constraints for normality, banal, click had to change? I don’t mind the version bumps being included in this PR, I was just wondering about the reason behind it…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed click, that was a mistake (not a terrible one, it current constraint just crapped click below the latest version).

banal and normality are libs we created. I bumped the minimum version to the latest version. Both of these were giving me dependency clashes with memorious.

Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
"pyyaml >= 5.0.0, < 7.0.0",
"types-PyYAML",
"sqlalchemy2-stubs",
"banal >= 1.0.1, < 1.1.0",
"banal >= 1.0.6, < 1.1.0",
"click >= 8.0, < 8.1.7",
"stringcase >= 1.2.0, < 2.0.0",
"requests >= 2.21.0, < 3.0.0",
"python-levenshtein >= 0.12.0, < 1.0.0",
"normality >= 2.1.1, < 3.0.0",
"sqlalchemy >= 1.2.0, < 3.0.0",
"normality >= 2.4.0, < 3.0.0",
"sqlalchemy >= 1.4.49, < 3.0.0",
"countrynames >= 1.13.0, < 2.0.0",
"languagecodes >= 1.1.0, < 2.0.0",
"prefixdate >= 0.4.0, < 1.0.0",
Expand Down