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

util.coerce_string_conf should coerce floats? #57

Closed
sqlalchemy-bot opened this issue Jan 9, 2014 · 4 comments
Closed

util.coerce_string_conf should coerce floats? #57

sqlalchemy-bot opened this issue Jan 9, 2014 · 4 comments
Labels
bug Something isn't working low priority

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Jeff Dairiki (dairiki)

Now that #9 has made it into release, I’m trying to use distributed_lock with the redis backend. I’ve discovered that one can not pleasantly configure lock_sleep to anything other than an integer or None when using configure_from_config (with a string-valued config dict, such as comes from a .ini settings file.) (Generally one wants to set lock_sleep to a value less than 1 second — e.g. the default is 0.1.)

My guess is that the simplest solution is to fix dogpile.cache.util.coerce_string_conf so that it coerces strings that look like floats to floats. I’m not quite sure whether that might screw something else up, however.

I'd be happy to produce a pull request if this is deemed the right way to proceed.


E.g.

from dogpile.cache import make_region

myregion = make_region()

myconfig = {
    "cache.backend":"dogpile.cache.redis",
    "cache.arguments.distributed_lock":"true",
    "cache.arguments.lock_timeout":"10",
    "cache.arguments.lock_sleep":"0.1",
}

myregion.configure_from_config(myconfig, "cache.")

print "lock_timeout = %r" % myregion.backend.lock_timeout
print "lock_sleep = %r" % myregion.backend.lock_sleep

myregion.get_or_create('somekey', lambda: 42)

which produces

lock_timeout = 10
lock_sleep = '0.1'

[traceback elided]
LockError: 'sleep' must be less than 'timeout'
@sqlalchemy-bot
Copy link
Author

Michael Bayer (zzzeek) wrote:

yeah I struggle with this coerce string thing in various projects, I've come up with a better solution for SQLAlchemy that allows explicit schemas per backend, but over here, certainly just looking for a decimal point and coercing to float in that case is a great solution for now, so feel free to send a pullreq.

@sqlalchemy-bot
Copy link
Author

Jeff Dairiki (dairiki) wrote:

I've just submitted pull request #13.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (zzzeek) wrote:

824df52 1f6c6b5

@sqlalchemy-bot
Copy link
Author

Changes by Michael Bayer (zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working low priority labels Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working low priority
Projects
None yet
Development

No branches or pull requests

1 participant