5

ArgumentError raises when passing plain text to "order_by". I'ts occurs with version 0.9.8, but not with version < 0.9.8 or > 0.9.8.

q = session.query(Person)
q.order_by('RAND()')
>> ArgumentError: Textual SQL expression 'RAND()' should be explicitly declared as text('RAND()')

questions: 1. Is there any official documentation about it? 2. With new versions, is this a good practice to pass plain text, or it is better to wrap it with text()? 3. Is this error raises with more functions other then order_by?

mclafee
  • 1,406
  • 3
  • 18
  • 25
  • @TimBiegeleisen the question was about the difference between sqlalchemy versions, and the right way to pass text to order_by. The option to use func.rand or text("RAND()") are well known. – mclafee Jun 10 '19 at 14:47
  • I couldn't reproduce this on any of 0.9.7, 0.9.8, or 0.9.9. Wrapping such constructs with `text()` is required since [1.3](https://docs.sqlalchemy.org/en/14/changelog/migration_13.html#coercion-of-string-sql-fragments-to-text-fully-removed). – snakecharmerb Apr 03 '22 at 07:36

0 Answers0