vutran1710 / PyrateLimiter

⚔️Python Rate-Limiter using Leaky-Bucket Algorithm Family
https://pyratelimiter.readthedocs.io
MIT License
334 stars 36 forks source link

SQLite Backend hard coded filename #169

Closed FridayPush closed 3 weeks ago

FridayPush commented 4 months ago

The Documentation for SQLite Backend does not mention the init_from_file function that is necessary to have the Table created. However that file has a hard coded "./mydb.sqlite", location. However if I pass in a connection and table using the example provided:

conn = sqlite3.connect(
    "async_test.sqlite",
    isolation_level="EXCLUSIVE",
    check_same_thread=False,
)
bucket = SQLiteBucket(rates, conn, "pyrate_table")

The table pyrate_table does not exist and the job fails with:

sqlite3.OperationalError: no such table: pyrate_table

Seems like there are a couple of possible action items:

vutran1710 commented 4 months ago

Sorry I got quite busy lately. Will fix it soon.

Silverlink34 commented 4 weeks ago

i can't even get it to work by hardcoding the mydb.sqlite:

def create_or_get_sqlite_bucket(bucketName, rates): connection = sqlite3.connect("mydb.sqlite", isolation_level="EXCLUSIVE", check_same_thread=False) bucket = SQLiteBucket(rates, connection, bucketName) return bucket

returns:

sqlite3.OperationalError: no such table: myBucketTable

vutran1710 commented 4 weeks ago

Issue acknowledged. Im going to fix it asap.

Silverlink34 commented 4 weeks ago

Issue acknowledged. Im going to fix it asap.

I appreciate your extremely quick response! In the meantime, I was considering going down the potential rabbit hole of overriding some sort of class. but if you are already implementing a fix so I can continue to treat it as "black box" code, then I would be most appreciative!!

vutran1710 commented 4 weeks ago

Resolved! Try again if you have time and let me if it works for you @Silverlink34

Silverlink34 commented 3 weeks ago

I apologize for the late response, I just updated and am still getting the same error:

File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 80, in __init__ self.bucket_factory = self._init_bucket_factory(argument, clock=clock) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 119, in _init_bucket_factory argument = SingleBucketFactory(argument, clock) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 43, in __init__ self.schedule_leak(bucket, clock) File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 263, in schedule_leak self._leaker.register(new_bucket, associated_clock) File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 134, in register try_leak = bucket.leak(0) ^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\buckets\sqlite_bucket.py", line 118, in leak count = self.conn.execute(query).fetchone()[0] ^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such table: openweathermap_bucket

vutran1710 commented 3 weeks ago

I apologize for the late response, I just updated and am still getting the same error:

File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 80, in __init__

self.bucket_factory = self._init_bucket_factory(argument, clock=clock)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 119, in _init_bucket_factory

argument = SingleBucketFactory(argument, clock)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 43, in __init__

self.schedule_leak(bucket, clock)

File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 263, in schedule_leak

self._leaker.register(new_bucket, associated_clock)

File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 134, in register

try_leak = bucket.leak(0)

^^^^^^^^^^^^^^

File "C:\Python312\Lib\site-packages\pyrate_limiter\buckets\sqlite_bucket.py", line 118, in leak

count = self.conn.execute(query).fetchone()[0]

^^^^^^^^^^^^^^^^^^^^^^^^

sqlite3.OperationalError: no such table: openweathermap_bucket

Can you provide some code snippet?

vutran1710 commented 3 weeks ago

I apologize for the late response, I just updated and am still getting the same error:

File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 80, in __init__ self.bucket_factory = self._init_bucket_factory(argument, clock=clock) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 119, in _init_bucket_factory argument = SingleBucketFactory(argument, clock) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 43, in __init__ self.schedule_leak(bucket, clock) File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 263, in schedule_leak self._leaker.register(new_bucket, associated_clock) File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 134, in register try_leak = bucket.leak(0) ^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\buckets\sqlite_bucket.py", line 118, in leak count = self.conn.execute(query).fetchone()[0] ^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such table: openweathermap_bucket

Can you try using an existing db located somewhere you can easily inspect, check for the table existence before running any bucket-creating code? Technically table should be created right after you init the Bucket.

Silverlink34 commented 3 weeks ago

I can check after work, give me a few hours please.

On Mon, Aug 12, 2024 at 12:27 PM Vu Tran @.***> wrote:

I apologize for the late response, I just updated and am still getting the same error:

File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 80, in init self.bucket_factory = self._init_bucket_factory(argument, clock=clock) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 119, in _init_bucket_factory argument = SingleBucketFactory(argument, clock) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\limiter.py", line 43, in init self.schedule_leak(bucket, clock) File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 263, in schedule_leak self._leaker.register(new_bucket, associated_clock) File "C:\Python312\Lib\site-packages\pyrate_limiter\abstracts\bucket.py", line 134, in register try_leak = bucket.leak(0) ^^^^^^^^^^^^^^ File "C:\Python312\Lib\site-packages\pyrate_limiter\buckets\sqlite_bucket.py", line 118, in leak count = self.conn.execute(query).fetchone()[0] ^^^^^^^^^^^^^^^^^^^^^^^^ sqlite3.OperationalError: no such table: openweathermap_bucket

Can you try using an existing db located somewhere you can easily inspect, check for the table existence before running any bucket-creating code? Technically table should be created right after you init the Bucket.

— Reply to this email directly, view it on GitHub https://github.com/vutran1710/PyrateLimiter/issues/169#issuecomment-2284447192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUHM3YGTPJEY34V7HH5QQTZRDO6XAVCNFSM6AAAAABGNSUQEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOBUGQ2DOMJZGI . You are receiving this because you were mentioned.Message ID: @.***>