Skip to content

Conversation

omad
Copy link
Member

@omad omad commented Sep 6, 2025

This should fix #667

I'm surprised it's intermittent, I would have thought it'd happen all the time, and it's probably happening in deployments too, not just in testing.


📚 Documentation preview 📚: https://datacube-explorer--830.org.readthedocs.build/en/830/

@omad omad requested a review from pjonsson September 6, 2025 00:41
@omad omad force-pushed the fix-use-after-close branch 3 times, most recently from 9d4d427 to e324c2d Compare September 6, 2025 05:14
@omad omad force-pushed the fix-use-after-close branch from e324c2d to 5020097 Compare September 6, 2025 05:16
@omad omad marked this pull request as draft September 6, 2025 05:35
region_code=r.region_code,
creation_time=r.creation_time,
center_time=r.center_time,
odc_dataset=(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since your name ends up in the git blame, you might be able to fit the parameter in a single line if you remove the parenthesis (not sure why the parenthesis was there in the first place).

You could also try taking the RHS of geometry= and putting that on a single line without its parenthesis and then ruff format, but I'm guessing Ruff will re-wrap that because the line is too long.

return conn.execute(query).fetchall()

@contextmanager
def execute_query_lazy(self, query):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the return type of this Generator[Row], or does the context manager decorator change the return types?

for row in result:
"""
with self.engine.connect() as conn:
result = conn.execute(query)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can yield conn.execute(query) directly?

@pjonsson
Copy link
Contributor

pjonsson commented Sep 6, 2025

The cursor closed error is really annoying so happy to approve if you can get this working, the code looks fine to me (but SQLAlchemy/psycopg2 does apparently not agree with us).

And I agree, the cursor closed probably happens in production as well.

@pjonsson
Copy link
Contributor

pjonsson commented Sep 6, 2025

I'm going to go to bed now, but I looked at this earlier today and all the failed tests failed in the same upsert method in the postgres backend. Might be worth to rebase this onto the latest develop and let it run to see if the other test jobs also fail, or if it just is upsert that is broken.

@omad omad closed this Sep 7, 2025
@omad omad deleted the fix-use-after-close branch September 11, 2025 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Intermittent psycopg2.InterfaceError: cursor already closed in tests
2 participants