deckar01 / ratelimit

API Rate Limit Decorator
MIT License
20 stars 2 forks source link

Function gets stuck for certain "name" arguments #5

Open om-hb opened 4 years ago

om-hb commented 4 years ago

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()
deckar01 commented 3 years ago

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.