Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling get_hosted_table_names on the Python websocketclients always returns None #2360

Open
tjader opened this issue Sep 7, 2023 · 0 comments
Labels
bug Concrete, reproducible bugs Python

Comments

@tjader
Copy link

tjader commented Sep 7, 2023

Bug Report

Steps to Reproduce:

When using the method get_hosted_table_names PerspectiveTornadoClient or PerspectiveAIOHTTPClient I always get back None

  1. Start the tornado streaming server (in the examples folder). This one has one table named data_source_one managed
  2. Run the following script
import asyncio
from perspective.client.aiohttp import PerspectiveAIOHTTPClient
from perspective.client.tornado import PerspectiveTornadoClient

async def main_current(client_cls):
    client = client_cls()
    try:
        await client.connect('ws://127.0.0.1:8080/websocket')
        names = await client.get_hosted_table_names()
        print(f"{client_cls.__name__} - current: {names}")
    finally:
        await client.terminate()

if __name__ == '__main__':
    for client_cls in [PerspectiveTornadoClient, PerspectiveAIOHTTPClient]:
        asyncio.run(main_current(client_cls))

Expected Result:

I would expect ['data_source_one'] to be printed.

Actual Result:

Instead of ['data_source_one'] , names is None.

Environment:

Using perspective 2.5.1 on Python 3.11 inside a conda environment

Additional Context:

I think the issue can be fixed inside the method perspective.client.base.PerspectiveClient:get_hosted_table_names.
If I understand the code correctly, this method should call self.post with a Future object, and return the future object instead.
I.e. something like

    def get_hosted_table_names(self):
        fut = asyncio.Future()
        msg = {"cmd": "get_hosted_table_names"}
        self.post(msg, future=fut)
        return fut

A hacky version of my exampe shows it works, although I'm not sure what type of future object you normally use

import asyncio
from perspective.client.aiohttp import PerspectiveAIOHTTPClient
from perspective.client.tornado import PerspectiveTornadoClient

async def main_working(client_cls):
    client = client_cls()
    try:
        await client.connect('ws://127.0.0.1:8080/websocket')

        # get_hosted_table_names is just a thin wrapper around the post function. 
        # this code replicates its functionality
        fut = asyncio.Future()
        client.post(msg = {"cmd": "get_hosted_table_names"}, future=fut)
        names = await fut
        print(f"{client_cls.__name__} - workaround: {names}")
    finally:
        await client.terminate()


if __name__ == '__main__':
    for client_cls in [PerspectiveTornadoClient, PerspectiveAIOHTTPClient]:      
        asyncio.run(main_working(client_cls))
@timkpaine timkpaine added bug Concrete, reproducible bugs Python labels Oct 31, 2023
winverma added a commit to winverma/perspective that referenced this issue Nov 3, 2023
Calling get_hosted_table_names on the Python websocketclients always returns None: Fixed!
winverma added a commit to winverma/perspective that referenced this issue Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Concrete, reproducible bugs Python
Projects
None yet
Development

No branches or pull requests

2 participants