Skip to content

Commit 3b8cb9b

Browse files
check that attribute comments do not start with a colon
1 parent bdfbd09 commit 3b8cb9b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

datajoint/declare.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def compile_attribute(line, in_key, foreign_key_sql):
393393
match = attribute_parser.parseString(line + '#', parseAll=True)
394394
except pp.ParseException as err:
395395
raise DataJointError('Declaration error in position {pos} in line:\n {line}\n{msg}'.format(
396-
line=err.args[0], pos=err.args[1], msg=err.args[2]))
396+
line=err.args[0], pos=err.args[1], msg=err.args[2])) from None
397397
match['comment'] = match['comment'].rstrip('#')
398398
if 'default' not in match:
399399
match['default'] = ''
@@ -414,6 +414,9 @@ def compile_attribute(line, in_key, foreign_key_sql):
414414
match['comment'] = match['comment'].replace('"', '\\"') # escape double quotes in comment
415415
category, type_match = match_type(match['type'])
416416

417+
if match['comment'].startswith(':'):
418+
raise DataJointError('An attribute comment must not start with a colon in comment "{comment}"'.format(**match))
419+
417420
if category in CUSTOM_TYPES:
418421
match['comment'] = ':{type}:{comment}'.format(**match) # insert custom type into comment
419422
if category == 'UUID':

tests/schema_external.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Attach(dj.Manual):
9595
# table for storing attachments
9696
attach : int
9797
----
98-
img : attach@share # attachments are stored as specified by dj.config['stores']['raw']
98+
img : attach@share # attachments are stored as specified by: dj.config['stores']['raw']
9999
txt : attach # attachments are stored directly in the database
100100
"""
101101

@@ -104,7 +104,7 @@ class Attach(dj.Manual):
104104
class Filepath(dj.Manual):
105105
definition = """
106106
# table for file management
107-
fnum : int
107+
fnum : int # test comment containing :
108108
---
109109
img : filepath@repo # managed files
110110
"""

0 commit comments

Comments
 (0)