events.action: opened
events.author: kostyachum
events.masked_author: username_0
events.text: The setup is very simple
  
  model
  ```python
  class Post(db.Entity):
      id = PrimaryKey(UUID, auto=True)
      title = Optional(str)
  ```
  
  
  code:
  ```python
  @db_session
  def test(text: str, limit: int = 20):
      set_sql_debug(True)
      return Post.select(lambda p: raw_sql(f"'{by_post.title}' <% (title || ' ' || description)"))
  ```
  
  the SQL produces is completely fine and runs as expected, by evaluating the lazy queryset crashes with the next error:
  ```
  INFO:pony.orm:GET CONNECTION FROM THE LOCAL POOL
  INFO:pony.orm:SWITCH TO AUTOCOMMIT MODE
  INFO:pony.orm.sql:SELECT "p"."id", "p"."user_id", "p"."created_at", "p"."title", "p"."type", "p"."location", "p"."description"
  FROM "post" "p"
  WHERE 'sale' % (title || ' ' || description)
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  <ipython-input-3-dcf7bea12933> in <module>
  ----> 1 test('sale')[:]
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in __getitem__(query, key)
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/utils/utils.py in cut_traceback(func, *args, **kwargs)
       76             if module_name.startswith('pony.utils') and tb.tb_frame.f_code.co_name == 'throw':
       77                 reraise(exc_type, exc, last_pony_tb)
  ---> 78             reraise(exc_type, exc, full_tb)
       79         finally:
       80             del exc, full_tb, tb, last_pony_tb
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/utils/utils.py in reraise(***failed resolving arguments***)
       93 else:
       94     def reraise(exc_type, exc, tb):
  ---> 95         try: raise exc.with_traceback(tb)
       96         finally: del exc, tb
       97 
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/utils/utils.py in cut_traceback(func, *args, **kwargs)
       59         return func(*args, **kwargs)
       60 
  ---> 61     try: return func(*args, **kwargs)
       62     except AssertionError: raise
       63     except Exception:
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in __getitem__(query, key)
     6182         if stop is None:
     6183             if not start:
  -> 6184                 return query._fetch()
     6185             else:
     6186                 return query._fetch(limit=None, offset=start)
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in _fetch(query, limit, offset, lazy)
     6189         return query._fetch(limit=stop-start, offset=start)
     6190     def _fetch(query, limit=None, offset=None, lazy=False):
  -> 6191         return QueryResult(query, limit, offset, lazy=lazy)
     6192     @cut_traceback
     6193     def fetch(query, limit=None, offset=None):
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in __init__(self, query, limit, offset, lazy)
     6296         self._limit = limit
     6297         self._offset = offset
  -> 6298         self._items = None if lazy else self._query._actual_fetch(limit, offset)
     6299         self._expr_type = translator.expr_type
     6300         self._col_names = translator.col_names
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in _actual_fetch(query, limit, offset)
     5829             items = cache.query_results.get(query_key)
     5830             if items is None:
  -> 5831                 cursor = database._exec_sql(sql, arguments)
     5832                 if isinstance(translator.expr_type, EntityMeta):
     5833                     entity = translator.expr_type
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in _exec_sql(database, sql, arguments, returning_id, start_transaction)
      947         try: new_id = provider.execute(cursor, sql, arguments, returning_id)
      948         except Exception as e:
  --> 949             connection = cache.reconnect(e)
      950             cursor = connection.cursor()
      951             if local.debug: log_sql(sql, arguments)
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in reconnect(cache, exc)
     1782         if exc is not None:
     1783             exc = getattr(exc, 'original_exc', exc)
  -> 1784             if not provider.should_reconnect(exc): reraise(*sys.exc_info())
     1785             if local.debug: log_orm('CONNECTION FAILED: %s' % exc)
     1786             connection = cache.connection
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/utils/utils.py in reraise(***failed resolving arguments***)
       93 else:
       94     def reraise(exc_type, exc, tb):
  ---> 95         try: raise exc.with_traceback(tb)
       96         finally: del exc, tb
       97 
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/core.py in _exec_sql(database, sql, arguments, returning_id, start_transaction)
      945         provider = database.provider
      946         t = time()
  --> 947         try: new_id = provider.execute(cursor, sql, arguments, returning_id)
      948         except Exception as e:
      949             connection = cache.reconnect(e)
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/dbproviders/postgres.py in execute(provider, cursor, sql, arguments, returning_id)
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/dbapiprovider.py in wrap_dbapi_exceptions(func, provider, *args, **kwargs)
       50         try:
       51             if provider.dialect != 'SQLite':
  ---> 52                 return func(provider, *args, **kwargs)
       53             else:
       54                 provider.local_exceptions.keep_traceback = True
  
  ~/.virtualenvs/cri/lib/python3.8/site-packages/pony/orm/dbproviders/postgres.py in execute(provider, cursor, sql, arguments, returning_id)
      254         else:
      255             if arguments is None: cursor.execute(sql)
  --> 256             else: cursor.execute(sql, arguments)
      257             if returning_id: return cursor.fetchone()[0]
      258 
  
  TypeError: dict is not a sequence
  ```
  
  
  pg_trgm docs for reference: https://www.postgresql.org/docs/12/pgtrgm.html
events.title: Crash when using "text % text" filtering of pg_trgm
events.type: issue