ratelimit icon indicating copy to clipboard operation
ratelimit copied to clipboard

Function gets stuck for certain "name" arguments

Open om-hb opened this issue 4 years ago • 1 comments

Hi,

as some might stumble upon the same problem.. I noticed that the limits decorator gets stuck without any warning or error message for some name arguments passed to it. The issue seems to be caused by "illegal" table names (containing special characters, starting with numbers, etc.). In my experience, this could be solved by quoting the name in "" (see also: What are valid table names in SQLite?).

Examples to reproduce:

Gets stuck:

@limits(calls=1, period=10, storage='test.db', name='abc?')
def foo():
    print('Hi!')

foo()

Works:

@limits(calls=1, period=10, storage='test.db', name='"'+'abc?'+'"')
def foo():
    print("Hi!")

foo()

om-hb avatar Jul 22 '20 16:07 om-hb

Sorry for the delay. Notifications defaulted to off for this fork. They are on now.

Adding quotes seems like a good way to support most table names. After that, if the table creation fails, it should probably let the error to bubble up. I will probably need to inspect the error message to differentiate "table test already exists" from syntax errors since they both raise the same type.

It might be a good idea to warn about the way the table name is injected into queries in the docs also. Maybe some day parameter substitution will work on table names.

deckar01 avatar Jan 05 '21 22:01 deckar01