changeset 456:b52ebc45b8e3

psql: fix RSM requests handling: the sub-query to get row number to filter on for `before` and `after` was missing some filters and thus incorrect. This has been fixed by re-using `_appendSourcesAndFilters`. rel: 399
author Goffi <goffi@goffi.org>
date Thu, 30 Sep 2021 16:55:05 +0200
parents 0b5233981671
children 7c9792f934a2
files sat_pubsub/pgsql_storage.py
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/pgsql_storage.py	Mon Aug 02 21:58:17 2021 +0200
+++ b/sat_pubsub/pgsql_storage.py	Thu Sep 30 16:55:05 2021 +0200
@@ -1182,9 +1182,14 @@
                     query[1] += f",row_number() OVER ({query_order}) as row_number"
                     query.append(f"{query_order}) as x")
                     query.append(
-                        f"WHERE row_number<(SELECT row_number FROM (SELECT row_number() OVER ({query_order}) as row_number,item FROM items WHERE node_id=%s) as row_num_sub WHERE item=%s)"
+                        "WHERE row_number<(SELECT row_number FROM (SELECT row_number() "
+                        f"OVER ({query_order}) as row_number,item"
                     )
-                    args.extend((self.nodeDbId, rsm.before))
+                    self._appendSourcesAndFilters(
+                        query, args, authorized_groups, unrestricted, ext_data
+                    )
+                    query.append(") as row_num_sub WHERE item=%s)")
+                    args.append(rsm.before)
                 # we need to reverse order in a first query to get the right
                 # items
                 query.insert(0,"SELECT * from (")
@@ -1204,9 +1209,14 @@
                 query[1] += f",row_number() OVER ({query_order}) as row_number"
                 query.append(f"{query_order}) as x")
                 query.append(
-                    f"WHERE row_number>(SELECT row_number FROM (SELECT row_number() OVER ({query_order}) as row_number,item FROM items WHERE node_id=%s) as row_num_sub WHERE item=%s)"
+                    "WHERE row_number>(SELECT row_number FROM (SELECT row_number() "
+                    f"OVER ({query_order}) as row_number,item"
                 )
-                args.extend((self.nodeDbId, rsm.after))
+                self._appendSourcesAndFilters(
+                    query, args, authorized_groups, unrestricted, ext_data
+                )
+                query.append(") as row_num_sub WHERE item=%s)")
+                args.append(rsm.after)
         else:
             rsm = False