@@ -131,11 +131,12 @@ def _fetch_records(jwt_payload: dict, schema_name: str, table_name: str,
131131
132132 # Get table object from name
133133 table = _DJConnector ._get_table_object (schema_virtual_module , table_name )
134-
134+ attributes = table . heading . attributes
135135 # Fetch tuples without blobs as dict to be used to create a
136136 # list of tuples for returning
137- query = table & dj .AndList ([_DJConnector ._filter_to_restriction (f )
138- for f in restriction ])
137+ query = table & dj .AndList ([
138+ _DJConnector ._filter_to_restriction (f , attributes [f ['attributeName' ]].type )
139+ for f in restriction ])
139140 non_blobs_rows = query .fetch (* table .heading .non_blobs , as_dict = True , limit = limit ,
140141 offset = (page - 1 )* limit , order_by = order )
141142
@@ -149,7 +150,7 @@ def _fetch_records(jwt_payload: dict, schema_name: str, table_name: str,
149150 row = []
150151 # Loop through each attributes, append to the tuple_to_return with specific
151152 # modification based on data type
152- for attribute_name , attribute_info in table . heading . attributes .items ():
153+ for attribute_name , attribute_info in attributes .items ():
153154 if not attribute_info .is_blob :
154155 if non_blobs_row [attribute_name ] is None :
155156 # If it is none then just append None
@@ -180,7 +181,7 @@ def _fetch_records(jwt_payload: dict, schema_name: str, table_name: str,
180181
181182 # Add the row list to tuples
182183 rows .append (row )
183- return list (table . heading . attributes .keys ()), rows , len (query )
184+ return list (attributes .keys ()), rows , len (query )
184185
185186 @staticmethod
186187 def _get_table_attributes (jwt_payload : dict , schema_name : str , table_name : str ) -> dict :
@@ -295,12 +296,14 @@ def _record_dependency(jwt_payload: dict, schema_name: str, table_name: str,
295296 _DJConnector ._set_datajoint_config (jwt_payload )
296297 virtual_module = dj .VirtualModule (schema_name , schema_name )
297298 table = getattr (virtual_module , table_name )
299+ attributes = table .heading .attributes
298300 # Retrieve dependencies of related to retricted
299301 dependencies = [dict (schema = descendant .database , table = descendant .table_name ,
300302 accessible = True , count = len (
301303 (table if descendant .full_table_name == table .full_table_name
302304 else descendant * table ) & dj .AndList ([
303- _DJConnector ._filter_to_restriction (f )
305+ _DJConnector ._filter_to_restriction (
306+ f , attributes [f ['attributeName' ]].type )
304307 for f in restriction ])))
305308 for descendant in table ().descendants (as_objects = True )]
306309 return dependencies
@@ -352,8 +355,10 @@ def _delete_records(jwt_payload: dict, schema_name: str, table_name: str,
352355
353356 # Get table object from name
354357 table = _DJConnector ._get_table_object (schema_virtual_module , table_name )
355-
356- restrictions = [_DJConnector ._filter_to_restriction (f ) for f in restriction ]
358+ attributes = table .heading .attributes
359+ restrictions = [
360+ _DJConnector ._filter_to_restriction (f , attributes [f ['attributeName' ]].type )
361+ for f in restriction ]
357362
358363 # Compute restriction
359364 query = table & dj .AndList (restrictions )
@@ -385,13 +390,15 @@ def _get_table_object(schema_virtual_module: VirtualModule, table_name: str) ->
385390 return getattr (schema_virtual_module , table_name_parts [0 ])
386391
387392 @staticmethod
388- def _filter_to_restriction (attribute_filter : dict ) -> str :
393+ def _filter_to_restriction (attribute_filter : dict , attribute_type : str ) -> str :
389394 """
390395 Convert attribute filter to a restriction.
391396
392397 :param attribute_filter: A filter as ``dict`` with ``attributeName``, ``operation``,
393398 ``value`` keys defined, defaults to ``[]``
394399 :type attribute_filter: dict
400+ :param attribute_type: Attribute type
401+ :type attribute_type: str
395402 :return: DataJoint-compatible restriction
396403 :rtype: str
397404 """
@@ -405,7 +412,8 @@ def _filter_to_restriction(attribute_filter: dict) -> str:
405412
406413 if (isinstance (attribute_filter ['value' ], str ) and
407414 not attribute_filter ['value' ].isnumeric ()):
408- value = f"'{ attribute_filter ['value' ]} '"
415+ value = (f"X'{ attribute_filter ['value' ].replace ('-' , '' )} '"
416+ if attribute_type == 'uuid' else f"'{ attribute_filter ['value' ]} '" )
409417 else :
410418 value = ('NULL' if attribute_filter ['value' ] is None
411419 else attribute_filter ['value' ])
0 commit comments