Skip to content

Unknown column error in restriction on a join product for dj 0.13.0 #899

@shenshan

Description

@shenshan

Bug Report

Related to #898 but a little different, when I do a restriction on a join product, there is a Unknown column error happens. This is only seen in 0.13.0, it was fine for 0.12.9.

Reproducibility

Same setting as #898, with the same code base:

import datajoint as dj
schema = dj.schema('test')

@schema
class Subject(dj.Manual):
    definition = """
    subject_id: varchar(32)
    ---
    dob : date
    sex : enum('M', 'F', 'U')
    """

@schema
class Session(dj.Manual):
    definition = """
    -> Subject
    session_start_time: datetime
    ---
    session_dir=''  : varchar(32)
    """

@schema
class SessionStatus(dj.Manual):
    definition = """
    -> Session
    ---
    status: enum('in_training', 'trained_1a', 'trained_1b', 'ready4ephys')
    """

@schema
class SessionDate(dj.Manual):
    definition = """
    -> Subject
    session_date:  date
    """

Subject.insert([
    ('mouse1', '2020-09-01', 'M'),
    ('mouse2', '2020-03-19', 'F'),
    ('mouse3', '2020-08-23', 'F')
])

Session.insert([
    ('mouse1', '2020-12-01 12:32:34', ''),
    ('mouse1', '2020-12-02 12:32:34', ''),
    ('mouse1', '2020-12-03 12:32:34', ''),
    ('mouse1', '2020-12-04 12:32:34', '')
])

SessionStatus.insert([
    ('mouse1', '2020-12-01 12:32:34', 'in_training'),
    ('mouse1', '2020-12-02 12:32:34', 'trained_1a'),
    ('mouse1', '2020-12-03 12:32:34', 'trained_1b'),
    ('mouse1', '2020-12-04 12:32:34', 'ready4ephys'),
])

SessionDate.insert([
    ('mouse1', '2020-12-01'),
    ('mouse1', '2020-12-02'),
    ('mouse1', '2020-12-03'),
    ('mouse1', '2020-12-04')
])

subj_query = Subject.aggr(
    Session * SessionStatus & 'status="trained_1a" or status="trained_1b"', date_trained='min(date(session_start_time))')
(SessionDate * (subj_query & 'date_trained<"2020-12-21"')) & 'session_date<"date_trained"'

gives an error:

---------------------------------------------------------------------------
UnknownAttributeError                     Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/anaconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    400                         if cls is not object \
    401                                 and callable(cls.__dict__.get('__repr__')):
--> 402                             return _repr_pprint(obj, self, cycle)
    403 
    404             return _default_pprint(obj, self, cycle)

~/anaconda3/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    695     """A pprint that just redirects to the normal repr function."""
    696     # Find newlines and replace them with p.break_()
--> 697     output = repr(obj)
    698     for idx,output_line in enumerate(output.splitlines()):
    699         if idx:

~/anaconda3/lib/python3.7/site-packages/datajoint/expression.py in __repr__(self)
    524         :rtype: str
    525         """
--> 526         return super().__repr__() if config['loglevel'].lower() == 'debug' else self.preview()
    527 
    528     def preview(self, limit=None, width=None):

~/anaconda3/lib/python3.7/site-packages/datajoint/expression.py in preview(self, limit, width)
    528     def preview(self, limit=None, width=None):
    529         """ :return: a string of preview of the contents of the query. """
--> 530         return preview(self, limit, width)
    531 
    532     def _repr_html_(self):

~/anaconda3/lib/python3.7/site-packages/datajoint/preview.py in preview(query_expression, limit, width)
     11     if width is None:
     12         width = config['display.width']
---> 13     tuples = rel.fetch(limit=limit + 1, format="array")
     14     has_more = len(tuples) > limit
     15     tuples = tuples[:limit]

~/anaconda3/lib/python3.7/site-packages/datajoint/fetch.py in __call__(self, offset, limit, order_by, format, as_dict, squeeze, download_path, *attrs)
    191         else:  # fetch all attributes as a numpy.record_array or pandas.DataFrame
    192             cur = self._expression.cursor(
--> 193                 as_dict=as_dict, limit=limit, offset=offset, order_by=order_by)
    194             heading = self._expression.heading
    195             if as_dict:

~/anaconda3/lib/python3.7/site-packages/datajoint/expression.py in cursor(self, offset, limit, order_by, as_dict)
    514             sql += ' LIMIT %d' % limit + (' OFFSET %d' % offset if offset else "")
    515         logger.debug(sql)
--> 516         return self.connection.query(sql, as_dict=as_dict)
    517 
    518     def __repr__(self):

~/anaconda3/lib/python3.7/site-packages/datajoint/connection.py in query(self, query, args, as_dict, suppress_warnings, reconnect)
    300         cursor = self._conn.cursor(cursor=cursor_class)
    301         try:
--> 302             self._execute_query(cursor, query, args, suppress_warnings)
    303         except errors.LostConnectionError:
    304             if not reconnect:

~/anaconda3/lib/python3.7/site-packages/datajoint/connection.py in _execute_query(cursor, query, args, suppress_warnings)
    266                 cursor.execute(query, args)
    267         except client.err.Error as err:
--> 268             raise translate_query_error(err, query)
    269 
    270     def query(self, query, args=(), *, as_dict=False, suppress_warnings=True, reconnect=None):

UnknownAttributeError: Unknown column 'date_trained' in 'where clause'

---------------------------------------------------------------------------
UnknownAttributeError                     Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    343             method = get_real_method(obj, self.print_method)
    344             if method is not None:
--> 345                 return method()
    346             return None
    347         else:

~/anaconda3/lib/python3.7/site-packages/datajoint/expression.py in _repr_html_(self)
    532     def _repr_html_(self):
    533         """ :return: HTML to display table in Jupyter notebook. """
--> 534         return repr_html(self)
    535 
    536 

~/anaconda3/lib/python3.7/site-packages/datajoint/preview.py in repr_html(query_expression)
     32     rel = query_expression.proj(*heading.non_blobs)
     33     info = heading.table_status
---> 34     tuples = rel.fetch(limit=config['display.limit'] + 1, format='array')
     35     has_more = len(tuples) > config['display.limit']
     36     tuples = tuples[0:config['display.limit']]

~/anaconda3/lib/python3.7/site-packages/datajoint/fetch.py in __call__(self, offset, limit, order_by, format, as_dict, squeeze, download_path, *attrs)
    191         else:  # fetch all attributes as a numpy.record_array or pandas.DataFrame
    192             cur = self._expression.cursor(
--> 193                 as_dict=as_dict, limit=limit, offset=offset, order_by=order_by)
    194             heading = self._expression.heading
    195             if as_dict:

~/anaconda3/lib/python3.7/site-packages/datajoint/expression.py in cursor(self, offset, limit, order_by, as_dict)
    514             sql += ' LIMIT %d' % limit + (' OFFSET %d' % offset if offset else "")
    515         logger.debug(sql)
--> 516         return self.connection.query(sql, as_dict=as_dict)
    517 
    518     def __repr__(self):

~/anaconda3/lib/python3.7/site-packages/datajoint/connection.py in query(self, query, args, as_dict, suppress_warnings, reconnect)
    300         cursor = self._conn.cursor(cursor=cursor_class)
    301         try:
--> 302             self._execute_query(cursor, query, args, suppress_warnings)
    303         except errors.LostConnectionError:
    304             if not reconnect:

~/anaconda3/lib/python3.7/site-packages/datajoint/connection.py in _execute_query(cursor, query, args, suppress_warnings)
    266                 cursor.execute(query, args)
    267         except client.err.Error as err:
--> 268             raise translate_query_error(err, query)
    269 
    270     def query(self, query, args=(), *, as_dict=False, suppress_warnings=True, reconnect=None):

UnknownAttributeError: Unknown column 'date_trained' in 'where clause'

Metadata

Metadata

Labels

bugIndicates an unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions