Skip to content

Commit 1a35ad0

Browse files
Fix connection access issue.
1 parent a943ad6 commit 1a35ad0

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

datajoint/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ def purge_query_cache(self):
235235
path_iter = pathlib.Path(config['query_cache']).glob('**/*')
236236
for path in path_iter:
237237
path.unlink()
238-
self._query_cache = None
239238

240239
def close(self):
241240
self._conn.close()

docs-parts/queries/12-Query-Caching_lang1.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
# set the query cache path
55
dj.config['query_cache'] = os.path.expanduser('~/dj_query_cache')
66
7-
# access the currently active connection object
8-
conn = dj.conn()
9-
## OR
10-
conn = schema.connection
11-
## OR
12-
conn = table.connection
7+
# access the active connection object for the tables
8+
conn = dj.conn() # if queries co-located with tables
9+
conn = module.schema.connection # if schema co-located with tables
10+
conn = module.table.connection # most flexible
1311
1412
# activate query caching for a namespace called 'main'
1513
conn.set_query_cache(query_cache='main')

tests/test_fetch.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,28 +261,29 @@ def test_query_caching(self):
261261
os.mkdir(os.path.expanduser('~/dj_query_cache'))
262262

263263
with dj.config(query_cache=os.path.expanduser('~/dj_query_cache')):
264+
conn = schema.TTest3.connection
264265
# insert sample data and load cache
265266
schema.TTest3.insert([dict(key=100+i, value=200+i) for i in range(2)])
266-
dj.conn().set_query_cache(query_cache='main')
267+
conn.set_query_cache(query_cache='main')
267268
cached_res = schema.TTest3().fetch()
268269
# attempt to insert while caching enabled
269270
try:
270271
schema.TTest3.insert([dict(key=200+i, value=400+i) for i in range(2)])
271-
assert False, 'Insert allowed which query caching enabled'
272+
assert False, 'Insert allowed while query caching enabled'
272273
except dj.DataJointError:
273-
dj.conn().set_query_cache()
274+
conn.set_query_cache()
274275
# insert new data
275276
schema.TTest3.insert([dict(key=600+i, value=800+i) for i in range(2)])
276277
# re-enable cache to access old results
277-
dj.conn().set_query_cache(query_cache='main')
278+
conn.set_query_cache(query_cache='main')
278279
previous_cache = schema.TTest3().fetch()
279280
# verify properly cached and how to refresh results
280281
assert all([c == p for c, p in zip(cached_res, previous_cache)])
281-
dj.conn().set_query_cache()
282+
conn.set_query_cache()
282283
uncached_res = schema.TTest3().fetch()
283284
assert len(uncached_res) > len(cached_res)
284285
# purge query cache
285-
dj.conn().purge_query_cache()
286+
conn.purge_query_cache()
286287

287288
# reset cache directory state (will fail if purge was unsuccessful)
288289
os.rmdir(os.path.expanduser('~/dj_query_cache'))

0 commit comments

Comments
 (0)