Skip to content

Commit 30d91d7

Browse files
Merge pull request #342 from guzman-raphael/abstract-instantiation
Fix issue with double colon attribute comment parsing and dj.config initial load
2 parents b4c0102 + a46653d commit 30d91d7

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

+dj/+internal/Header.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@
9292
attrs.database{i} = schema.dbname;
9393
attrs.sqlType{i} = attrs.type{i};
9494
attrs.sqlComment{i} = attrs.comment{i};
95-
special = regexp(attrs.comment{i}, ':([^:]+):(.*)', 'tokens');
95+
special = regexp(attrs.comment{i}, ...
96+
'^:(?<type>[^: ,()]+):(?<comment>.*)', 'names');
9697
if ~isempty(special)
97-
attrs.type{i} = special{1}{1};
98-
attrs.comment{i} = special{1}{2};
98+
attrs.type{i} = special.type;
99+
attrs.comment{i} = special.comment;
99100
category = dj.internal.Declare.matchType(attrs.type{i});
100101
assert(any(strcmpi(category, dj.internal.Declare.SPECIAL_TYPES)));
101102
else

+dj/+internal/Settings.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,14 @@ function envVarUpdate()
147147
% return STATE prior to change
148148
out = STATE;
149149
if any(strcmpi(operation, {'set', 'load'}))
150-
% merge with existing STATE
151-
STATE = rmfield(STATE, intersect(fieldnames(STATE), fieldnames(new)));
152-
names = [fieldnames(STATE); fieldnames(new)];
153-
STATE = orderfields(cell2struct([struct2cell(STATE); struct2cell(new)], names, 1));
150+
if isempty(STATE)
151+
STATE = new;
152+
else
153+
% merge with existing STATE
154+
STATE = rmfield(STATE, intersect(fieldnames(STATE), fieldnames(new)));
155+
names = [fieldnames(STATE); fieldnames(new)];
156+
STATE = orderfields(cell2struct([struct2cell(STATE); struct2cell(new)], names, 1));
157+
end
154158
if strcmpi(operation, 'load')
155159
envVarUpdate();
156160
end

docs-parts/intro/Releases_lang1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
--------------------------
33
* Bugfix: Error on accessing unmanaged Imported/Computed tables (#336) PR #338
44
* Bugfix: Certain characters in attribute comment not escaped properly (#210, #335) PR #338
5+
* Bugfix: `dj.config.load(...)` after initial MATLAB boot throws invalid input error. PR #338
56

67
3.4.0 -- December 11, 2020
78
--------------------------

tests/TestConfig.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ function TestConfig_testLoad(testCase)
197197
base = regexprep(base,'[a-z0-9][A-Z]','${$0(1)}_${lower($0(2))}');
198198
TestConfig.TestConfig_configSingleFileTest(testCase, 'load-custom', ...
199199
[pkg_path '/test_schemas/config_lite.json'], jsondecode(base));
200+
% test load on launch MATLAB
201+
clear functions;
202+
dj.config.load([pkg_path '/test_schemas/config_lite.json']);
200203
% cleanup
201204
dj.config.restore;
202205
end

tests/test_schemas/+University/Message.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Message
33
msg_id : uuid # (this) is: a test of 'an' (elaborate), /type: of "comment" (good luck?)
44
---
5-
body : varchar(30)
5+
body : varchar(30) # (try) with: double colon (to), throw: it (off)
66
dep_id=null : uuid
77
%}
88
classdef Message < dj.Manual

0 commit comments

Comments
 (0)