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

AttributeError when using sqlite backend #230

Closed
cheginit opened this issue Apr 6, 2024 · 3 comments · Fixed by #233
Closed

AttributeError when using sqlite backend #230

cheginit opened this issue Apr 6, 2024 · 3 comments · Fixed by #233
Labels
bug Something isn't working
Milestone

Comments

@cheginit
Copy link

cheginit commented Apr 6, 2024

The problem

In my package, I have two tests for checking caching. When I run the tests with pytest, I get this warning:

  /Users/tchegini/repos/hyriver/async-retriever/.nox/tests-3-9/lib/python3.9/site-packages/_pytest/unraisableexception.py:80: PytestUnraisableExceptionWarning: Exception ignored in: <function SQLiteCache.__del__ at 0x104f849d0>

  Traceback (most recent call last):
    File "/Users/tchegini/repos/hyriver/async-retriever/.nox/tests-3-9/lib/python3.9/site-packages/aiohttp_client_cache/backends/sqlite.py", line 116, in __del__
      self._connection._tx.queue.clear()
  AttributeError: '_queue.SimpleQueue' object has no attribute 'queue'

    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

As the traceback shows, this warning is suppressed and only shows up with pytest and not when running the code.

Expected behavior

I am not sure if this behavior is intentional or not.

Steps to reproduce the behavior

from pathlib import Path
import asyncio

from aiohttp_client_cache import SQLiteBackend

import async_retriever as ar

SMALL = 1e-3


async def check_url(url, method="GET", **kwargs):
    cache = SQLiteBackend(cache_name=Path("cache", "aiohttp_cache.sqlite"))
    return await cache.has_url(url, method, **kwargs)


def test_disable_cache():
    url = "https://epqs.nationalmap.gov/v1/json"
    payload = {"params": {"x": -101, "y": 38, "units": "Meters"}}
    resp = ar.retrieve([url], "json", [payload], disable=True)
    elev = float(resp[0]["value"])
    assert abs(elev - 880.418) < SMALL
    assert not asyncio.run(check_url(url, params=payload["params"]))


def test_delete_url():
    url = "https://epqs.nationalmap.gov/v1/json"
    payload = {"params": {"x": -100, "y": 38, "units": "Meters"}}
    resp = ar.retrieve([url], "json", [payload])
    elev = float(resp[0]["value"])
    ar.delete_url_cache(url, params=payload["params"])
    assert abs(elev - 761.684) < SMALL
    assert not asyncio.run(check_url(url, params=payload["params"]))

Workarounds

N/A

Environment

  • aiohttp-client-cache version: 0.11.0
  • Python version: 3.11
  • Platform: MacOS Sonoma
@cheginit cheginit added the bug Something isn't working label Apr 6, 2024
@JWCook
Copy link
Member

JWCook commented Apr 12, 2024

It appears that aiosqlite 0.20 changed its queue implementation in omnilib/aiosqlite#271.

On this end, I'm using some of aiosqlite's internals to force its connection thread to end in order to avoid hanging if the application exits without using the CachedSession contextmanager or calling .close() (see #173, #187, #189).

So that's not their fault. I'll get that fixed soon.

@JWCook
Copy link
Member

JWCook commented Apr 12, 2024

@cheginit Test out the changes in main when you get the chance, and let me know if that fixes the issue for you.

@cheginit
Copy link
Author

cheginit commented Apr 12, 2024

I just checked with main, and it runs without throwing the warning. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants