Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix leading slash issue on insert into remote storage.
  • Loading branch information
guzman-raphael committed Nov 8, 2019
commit c9e6decf4bd7a60025a5db798d10b67f78b399e8
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Release notes

### 0.12.2 -- Nov 8, 2019
* Bugfix - Insert into external does not trim leading slash if defined in `dj.config['stores']['<store>']['location']` (#692)

### 0.12.1 -- Nov 2, 2019
* Bugfix - AttributeAdapter converts into a string (#684)

Expand Down
9 changes: 7 additions & 2 deletions datajoint/external.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pathlib import Path, PurePosixPath
from pathlib import Path, PurePosixPath, PureWindowsPath
from collections import Mapping
from tqdm import tqdm
from .settings import config
Expand Down Expand Up @@ -74,7 +74,12 @@ def s3(self):

def _make_external_filepath(self, relative_filepath):
"""resolve the complete external path based on the relative path"""
return PurePosixPath(Path(self.spec['location']), relative_filepath)
posix_path = PurePosixPath(PureWindowsPath(self.spec['location']))
location_path = Path(
*posix_path.parts[1:]) if any(
case in posix_path.parts[0] for case in (
'\\', ':')) else Path(posix_path)
return PurePosixPath(location_path, relative_filepath)

def _make_uuid_path(self, uuid, suffix=''):
"""create external path based on the uuid hash"""
Expand Down
2 changes: 1 addition & 1 deletion datajoint/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.12.1"
__version__ = "0.12.2"

assert len(__version__) <= 10 # The log table limits version to the 10 characters
4 changes: 4 additions & 0 deletions docs-parts/intro/Releases_lang1.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.12.1 -- Nov 8, 2019
-------------------------
* Bugfix - Insert into external does not trim leading slash if defined in `dj.config['stores']['<store>']['location']` (#692)

0.12.1 -- Nov 2, 2019
-------------------------
* Bugfix - AttributeAdapter converts into a string (#684)
Expand Down
9 changes: 9 additions & 0 deletions tests/schema_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class Simple(dj.Manual):
"""


@schema
class SimpleRemote(dj.Manual):
definition = """
simple : int
---
item : blob@share
"""


@schema
class Seed(dj.Lookup):
definition = """
Expand Down
32 changes: 32 additions & 0 deletions tests/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .schema_external import schema
import datajoint as dj
from .schema_external import stores_config
from .schema_external import SimpleRemote


def setUp(self):
Expand All @@ -33,3 +34,34 @@ def test_external_put():

output_ = unpack(ext.get(hash1))
assert_array_equal(input_, output_)


def test_leading_slash():
"""
external storage configured with leading slash
"""
value = np.array([1, 2, 3])

id = 100
dj.config['stores']['share']['location'] = 'leading/slash/test'
SimpleRemote.insert([{'simple': id, 'item': value}])
assert_true(np.array_equal(
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))

id = 101
dj.config['stores']['share']['location'] = '/leading/slash/test'
SimpleRemote.insert([{'simple': id, 'item': value}])
assert_true(np.array_equal(
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))

id = 102
dj.config['stores']['share']['location'] = 'leading\\slash\\test'
SimpleRemote.insert([{'simple': id, 'item': value}])
assert_true(np.array_equal(
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))

id = 103
dj.config['stores']['share']['location'] = 'f:\\leading\\slash\\test'
SimpleRemote.insert([{'simple': id, 'item': value}])
assert_true(np.array_equal(
value, (SimpleRemote & 'simple={}'.format(id)).fetch1('item')))