Skip to content

Commit 9e6fff7

Browse files
Merge pull request #165 from guzman-raphael/conn-existing
Fix error that triggers when a connection is already established.
2 parents f5aa5c1 + e45b411 commit 9e6fff7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

+dj/conn.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232

3333

3434
if isa(CONN, 'dj.Connection') && ~reset
35-
assert(nargin==0, ...
36-
'connection already instantiated. To reconnect, clear functions')
35+
if nargin>0
36+
warning(sprintf(['Connection already instantiated.\n' ...
37+
'Will use existing connection to "' CONN.host '".\n' ...
38+
'To reconnect, set reset to true']));
39+
end
3740
else
3841
% invoke setupDJ
3942
% optional environment variables specifying the connection.

+tests/TestConnection.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,13 @@ function testConnection(testCase)
99
testCase.CONN_INFO.user,...
1010
testCase.CONN_INFO.password,'',true).isConnected);
1111
end
12+
function testConnectionExists(testCase)
13+
% testConnectionExists tests that will not fail if connection open.
14+
% Fix https://github.com/datajoint/datajoint-matlab/issues/160
15+
st = dbstack;
16+
disp(['---------------' st(1).name '---------------']);
17+
dj.conn(testCase.CONN_INFO.host, '', '', '', '', true)
18+
dj.conn(testCase.CONN_INFO.host, '', '', '', '', true)
19+
end
1220
end
1321
end

0 commit comments

Comments
 (0)