                       (jdbc/with-db-connection db
                         (jdbc/with-db-transaction []
                           (let [{:keys [results-query count-query]}
-                                (query->sql query entity version query-options
-                                            {:log-id log-id})
+                                (query->sql query entity version query-options context)
                                 st (when count-query
                                      {:count (jdbc/get-result-count count-query)})
                                 stream-row (fn [row]

                  (events/legacy-query->sql false version query options)

                  :else (regular-query->sql query entity options))]
     (when-let [log-id (:log-id context)]
       (let [{[sql & params] :results-query} result]
         (log/infof "PDBQuery:%s:%s"
                    log-id (-> (sorted-map :origin (:origin options)
                                           :sql sql
                                           :params (vec params))
                               json/generate-string))))
     result)))

(defn get-munge-fn

  [version :- s/Keyword
   query-map
   context :- query-context-schema]
  ;; For now, generate the ids here; perhaps later, higher up
  (assert (not (:query-id context)))
  (let [context (assoc context :query-id (str (java.util.UUID/randomUUID)))]
    (if use-preferred-streaming-method?
      (preferred-produce-streaming-body version query-map context)
      (deprecated-produce-streaming-body version query-map context))))

(pls/defn-validated object-exists? :- s/Bool
  "Returns true if an object exists."
