Skip to content

Commit

Permalink
Merge pull request #341 from joke2k/fix/pymemcached-url-parsing
Browse files Browse the repository at this point in the history
Fix memcache/pymemcache URL parsing
  • Loading branch information
sergeyklay committed Oct 19, 2021
2 parents 7361c91 + 0a22b16 commit e1232cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Fixed
+++++
- Fixed "Invalid line" spam logs on blank lines in env file
`#340 <https://github.com/joke2k/django-environ/issues/340>`_.
- Fixed ``memcache``/``pymemcache`` URL parsing for correct identification of
connection type `#337 <https://github.com/joke2k/django-environ/issues/337>`_.


`v0.8.0`_ - 17-October-2021
Expand Down
10 changes: 9 additions & 1 deletion environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,15 @@ def cache_url_config(cls, url, backend=None):
'LOCATION': url.netloc + url.path,
})

if url.path and url.scheme in ['memcache', 'pymemcache']:
# urlparse('pymemcache://127.0.0.1:11211')
# => netloc='127.0.0.1:11211', path=''
#
# urlparse('pymemcache://memcached:11211/?key_prefix=ci')
# => netloc='memcached:11211', path='/'
#
# urlparse('memcache:///tmp/memcached.sock')
# => netloc='', path='/tmp/memcached.sock'
if not url.netloc and url.scheme in ['memcache', 'pymemcache']:
config.update({
'LOCATION': 'unix:' + url.path,
})
Expand Down
4 changes: 4 additions & 0 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def test_base_options_parsing():
('pymemcache://127.0.0.1:11211',
PYMEMCACHE_DRIVER,
'127.0.0.1:11211'),
('pymemcache://memcached:11211/?key_prefix=ci',
PYMEMCACHE_DRIVER,
'memcached:11211'),
],
ids=[
'dbcache',
Expand All @@ -84,6 +87,7 @@ def test_base_options_parsing():
'memcached_multiple',
'memcached',
'pylibmccache',
'pylibmccache_trailing_slash',
],
)
def test_cache_parsing(url, backend, location):
Expand Down

0 comments on commit e1232cb

Please sign in to comment.