mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
message_fetch: Use modern select() calling style.
Fixes this warning with SQLALCHEMY_WARN_20=1: RemovedIn20Warning: The legacy calling style of select() is deprecated and will be removed in SQLAlchemy 2.0. Please use the new calling style described at select(). (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9) Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
8769c0c485
commit
fbb8f54d80
@@ -100,7 +100,7 @@ class NarrowBuilderTest(ZulipTestCase):
|
||||
self.realm = get_realm("zulip")
|
||||
self.user_profile = self.example_user("hamlet")
|
||||
self.builder = NarrowBuilder(self.user_profile, column("id", Integer), self.realm)
|
||||
self.raw_query = select([column("id", Integer)], None, table("zerver_message"))
|
||||
self.raw_query = select(column("id", Integer)).select_from(table("zerver_message"))
|
||||
self.hamlet_email = self.example_user("hamlet").email
|
||||
self.othello_email = self.example_user("othello").email
|
||||
|
||||
@@ -3341,7 +3341,9 @@ class GetOldMessagesTest(ZulipTestCase):
|
||||
]
|
||||
|
||||
muting_conditions = exclude_muting_conditions(user_profile, narrow)
|
||||
query = select([column("id", Integer).label("message_id")], None, table("zerver_message"))
|
||||
query = select(column("id", Integer).label("message_id")).select_from(
|
||||
table("zerver_message")
|
||||
)
|
||||
query = query.where(*muting_conditions)
|
||||
expected_query = """\
|
||||
SELECT id AS message_id \n\
|
||||
@@ -3366,7 +3368,7 @@ WHERE NOT (recipient_id = %(recipient_id_1)s AND upper(subject) = upper(%(param_
|
||||
]
|
||||
|
||||
muting_conditions = exclude_muting_conditions(user_profile, narrow)
|
||||
query = select([column("id", Integer)], None, table("zerver_message"))
|
||||
query = select(column("id", Integer)).select_from(table("zerver_message"))
|
||||
query = query.where(and_(*muting_conditions))
|
||||
|
||||
expected_query = """\
|
||||
|
||||
@@ -118,7 +118,7 @@ def ts_locs_array(
|
||||
match_pos = func.sum(part_len, type_=Integer).over(rows=(None, -1)) + len(TS_STOP)
|
||||
match_len = func.strpos(part, TS_STOP, type_=Integer) - 1
|
||||
return func.array(
|
||||
select([postgresql.array([match_pos, match_len])]).offset(1).scalar_subquery(),
|
||||
select(postgresql.array([match_pos, match_len])).offset(1).scalar_subquery(),
|
||||
type_=ARRAY(Integer),
|
||||
)
|
||||
|
||||
@@ -774,29 +774,33 @@ def get_base_query_for_search(
|
||||
# Handle the simple case where user_message isn't involved first.
|
||||
if not need_user_message:
|
||||
assert need_message
|
||||
query = select([column("id", Integer).label("message_id")], None, table("zerver_message"))
|
||||
query = select(column("id", Integer).label("message_id")).select_from(
|
||||
table("zerver_message")
|
||||
)
|
||||
inner_msg_id_col = literal_column("zerver_message.id", Integer)
|
||||
return (query, inner_msg_id_col)
|
||||
|
||||
assert user_profile is not None
|
||||
if need_message:
|
||||
query = select(
|
||||
[column("message_id", Integer), column("flags", Integer)],
|
||||
column("user_profile_id", Integer) == literal(user_profile.id),
|
||||
query = (
|
||||
select(column("message_id", Integer), column("flags", Integer))
|
||||
.where(column("user_profile_id", Integer) == literal(user_profile.id))
|
||||
.select_from(
|
||||
join(
|
||||
table("zerver_usermessage"),
|
||||
table("zerver_message"),
|
||||
literal_column("zerver_usermessage.message_id", Integer)
|
||||
== literal_column("zerver_message.id", Integer),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
inner_msg_id_col = column("message_id", Integer)
|
||||
return (query, inner_msg_id_col)
|
||||
|
||||
query = select(
|
||||
[column("message_id", Integer), column("flags", Integer)],
|
||||
column("user_profile_id", Integer) == literal(user_profile.id),
|
||||
table("zerver_usermessage"),
|
||||
query = (
|
||||
select(column("message_id", Integer), column("flags", Integer))
|
||||
.where(column("user_profile_id", Integer) == literal(user_profile.id))
|
||||
.select_from(table("zerver_usermessage"))
|
||||
)
|
||||
inner_msg_id_col = column("message_id", Integer)
|
||||
return (query, inner_msg_id_col)
|
||||
@@ -1076,7 +1080,9 @@ def get_messages_backend(
|
||||
)
|
||||
|
||||
main_query = query.subquery()
|
||||
query = select(main_query.c, None, main_query).order_by(column("message_id", Integer).asc())
|
||||
query = (
|
||||
select(*main_query.c).select_from(main_query).order_by(column("message_id", Integer).asc())
|
||||
)
|
||||
# This is a hack to tag the query we use for testing
|
||||
query = query.prefix_with("/* get_messages */")
|
||||
rows = list(sa_conn.execute(query).fetchall())
|
||||
@@ -1328,18 +1334,22 @@ def messages_in_narrow_backend(
|
||||
msg_ids = [message_id for message_id in msg_ids if message_id >= first_visible_message_id]
|
||||
# This query is limited to messages the user has access to because they
|
||||
# actually received them, as reflected in `zerver_usermessage`.
|
||||
query = select(
|
||||
[column("message_id", Integer), topic_column_sa(), column("rendered_content", Text)],
|
||||
query = (
|
||||
select(column("message_id", Integer), topic_column_sa(), column("rendered_content", Text))
|
||||
.where(
|
||||
and_(
|
||||
column("user_profile_id", Integer) == literal(user_profile.id),
|
||||
column("message_id", Integer).in_(msg_ids),
|
||||
),
|
||||
)
|
||||
)
|
||||
.select_from(
|
||||
join(
|
||||
table("zerver_usermessage"),
|
||||
table("zerver_message"),
|
||||
literal_column("zerver_usermessage.message_id", Integer)
|
||||
== literal_column("zerver_message.id", Integer),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
builder = NarrowBuilder(user_profile, column("message_id", Integer), user_profile.realm)
|
||||
|
||||
Reference in New Issue
Block a user