diff --git a/python/lsst/daf/butler/remote_butler/server/handlers/_external_query.py b/python/lsst/daf/butler/remote_butler/server/handlers/_external_query.py index 0747667c77..44023eba9a 100644 --- a/python/lsst/daf/butler/remote_butler/server/handlers/_external_query.py +++ b/python/lsst/daf/butler/remote_butler/server/handlers/_external_query.py @@ -96,20 +96,6 @@ def query_execute( assert False, "This line is unreachable." -def _retrieve_query_pages(ctx: _QueryContext, spec: ResultSpec) -> Iterator[QueryExecuteResultData]: - """Execute the database query and and return pages of results.""" - try: - print("before execute") - pages = ctx.driver.execute(spec, ctx.tree) - print("page1") - for page in pages: - yield convert_query_page(spec, page) - except ButlerUserError as e: - # If a user-facing error occurs, serialize it and send it to the - # client. - yield QueryErrorResultModel(error=serialize_butler_user_error(e)) - - # Instead of declaring this as a sync generator with 'def', it's async to # give us more control over the lifetime of exit_stack. StreamingResponse # ensures that this async generator is cancelled if the client @@ -148,10 +134,26 @@ async def _stream_query_pages( if message is None: done = True else: - yield message.model_dump_json() + message = message.model_dump_json() + print(f"{message=}") + yield message yield "\n" +def _retrieve_query_pages(ctx: _QueryContext, spec: ResultSpec) -> Iterator[QueryExecuteResultData]: + """Execute the database query and and return pages of results.""" + try: + print("before execute") + pages = ctx.driver.execute(spec, ctx.tree) + print("page1") + for page in pages: + yield convert_query_page(spec, page) + except ButlerUserError as e: + # If a user-facing error occurs, serialize it and send it to the + # client. + yield QueryErrorResultModel(error=serialize_butler_user_error(e)) + + async def _fetch_next_with_keepalives( iterator: AsyncIterator[QueryExecuteResultData], ) -> AsyncIterator[QueryExecuteResultData | None]: