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

TypeError: AsyncRealtimeChannel.subscribe.<locals>.on_join_push_timeout() takes 0 positional arguments but 1 was given #932

Closed
2 tasks done
blockfer-rp opened this issue Sep 26, 2024 · 1 comment · Fixed by supabase/realtime-py#208
Labels
bug Something isn't working

Comments

@blockfer-rp
Copy link

blockfer-rp commented Sep 26, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When attempting to subscribe to real-time changes on the trade_tokens table using Supabase's Python client, the connection fails with a timeout error. The error indicates that the on_join_push_timeout callback is incorrectly defined, causing a TypeError. This issue persists across different environments and servers, even with the latest version of Supabase installed and a clean Python environment.

To Reproduce

Steps to reproduce the behavior, including code snippets:

Setup Supabase Client:

import asyncio
import logging
from supabase._async.client import AsyncClient as Client, create_client
from supabase.lib.client_options import ClientOptions

# Enable basic logging
logging.basicConfig(level=logging.INFO)

# Supabase connection details
supabase_url = "https://dmwfqahwcgkglvwyzhiy.supabase.co"
supabase_key = "YOUR_SUPABASE_KEY"

async def create_supabase() -> Client:
    return await create_client(supabase_url, supabase_key)

Define Change Handler and Test Function:

def handle_changes(payload):
    logging.info(f"Change received: {payload}")

async def test_realtime():
    client = await create_supabase()
    logging.info("Connecting to Supabase realtime...")
    
    # Connect to Supabase real-time
    await client.realtime.connect()

    # Create channel and subscribe to changes
    channel = client.realtime.channel('trade-tokens-updates')
    await channel.on_postgres_changes(
        'INSERT',
        schema='public',
        table='trade_tokens',
        callback=handle_changes
    ).subscribe()

    # Keep the connection open
    try:
        logging.info("Listening for changes...")
        await asyncio.sleep(300)  # Keep running for 5 minutes
    except Exception as e:
        logging.error(f"An unexpected error occurred: {e}")
    finally:
        logging.info("Disconnecting...")
        await client.close()

if __name__ == "__main__":
    asyncio.run(test_realtime()) 

Observe the Error:

INFO:root:Connecting to Supabase realtime...
INFO:realtime._async.client:Connection was successful
INFO:root:send: {"topic": "realtime:trade-tokens-updates", "event": "phx_join", ...}
INFO:root:Listening for changes...
ERROR:root:join push timeout for channel realtime:trade-tokens-updates
...
TypeError: AsyncRealtimeChannel.subscribe.<locals>.on_join_push_timeout() takes 0 positional arguments but 1 was given

Expected behavior

The Supabase client should successfully subscribe to real-time changes on the trade_tokens table and invoke the handle_changes callback whenever a new INSERT event occurs. The connection should remain stable without timing out, allowing continuous listening for database changes.

System information

System Information
OS: Linux (Ubuntu 22.04)
Python Version: 3.11
Supabase Version: 2.7.4
Supabase Python Client: supabase-py

Additional context

The issue occurs despite having the latest Supabase version (2.7.4) installed.
A clean Python environment was used to rule out dependency conflicts.
The problem persists across different servers and local machines.
The error suggests that the on_join_push_timeout callback is incorrectly defined to accept no arguments, whereas it is invoked with one argument (payload).
Potential mismatch between callback signature and expected parameters in the realtime package.

INFO:root:Connecting to Supabase realtime...
INFO:realtime._async.client:Connection was successful
INFO:root:send: {"topic": "realtime:trade-tokens-updates", "event": "phx_join", "payload": {"config": {"broadcast": {"ack": false, "self": false}, "presence": {"key": ""}, "private": false, "postgres_changes": [{"event": "INSERT", "schema": "public", "table": "trade_tokens"}]}, "access_token": "X"}, "ref": "1", "join_ref": "1"}
INFO:root:Listening for changes...
ERROR:root:join push timeout for channel realtime:trade-tokens-updates
/home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/channel.py:88: RuntimeWarning: coroutine 'AsyncTimer.schedule_timeout' was never awaited
  self.rejoin_timer.schedule_timeout()
Object allocated at (most recent call last):
  File "/home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/channel.py", lineno 88
    self.rejoin_timer.schedule_timeout()
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-5' coro=<AsyncPush.start_timeout.<locals>.timeout() done, defined at /home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/push.py:83> exception=TypeError('AsyncRealtimeChannel.subscribe.<locals>.on_join_push_timeout() takes 0 positional arguments but 1 was given')>
Traceback (most recent call last):
  File "/home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/push.py", line 85, in timeout
    self.trigger("timeout", {})
  File "/home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/push.py", line 95, in trigger
    self.channel._trigger(self.ref_event, payload)
  File "/home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/channel.py", line 524, in _trigger
    binding.callback(payload, ref)
  File "/home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/push.py", line 79, in on_reply
    self._match_receive(**self.received_resp)
  File "/home/ramon/test/test_env/lib/python3.11/site-packages/realtime/_async/push.py", line 117, in _match_receive
    hook.callback(response)
TypeError: AsyncRealtimeChannel.subscribe.<locals>.on_join_push_timeout() takes 0 positional arguments but 1 was given

SOURCE CODE

import asyncio
import logging
from supabase._async.client import AsyncClient as Client, create_client
from supabase.lib.client_options import ClientOptions

# Enable basic logging
logging.basicConfig(level=logging.INFO)

# Supabase connection details
supabase_url = "https://dmwfqahwcgkglvwyzhiy.supabase.co"
supabase_key = "X"

async def create_supabase() -> Client:
    return await create_client(supabase_url, supabase_key)

def handle_changes(payload):
    logging.info(f"Change received: {payload}")

async def test_realtime():
    client = await create_supabase()
    logging.info("Connecting to Supabase realtime...")
    
    # Connect to Supabase real-time
    await client.realtime.connect()

    # Create channel and subscribe to changes
    channel = client.realtime.channel('trade-tokens-updates')
    await channel.on_postgres_changes(
        'INSERT',
        schema='public',
        table='trade_tokens',
        callback=handle_changes
    ).subscribe()

    # Keep the connection open
    try:
        logging.info("Listening for changes...")
        await asyncio.sleep(300)  # Keep running for 5 minutes
    except Exception as e:
        logging.error(f"An unexpected error occurred: {e}")
    finally:
        logging.info("Disconnecting...")
        await client.close()

if __name__ == "__main__":
    asyncio.run(test_realtime())

Verification of Real-time Enablement

Verified that real-time is enabled on the trade_tokens table by executing the following SQL command:

SELECT * FROM pg_publication_tables WHERE pubname = 'supabase_realtime';

Result:

[ { "pubname": "supabase_realtime", "schemaname": "public", "tablename": "trade_tokens", "attnames": "{id,quote_token_mint,wallet_public_key,amount_base_token_to_spend,take_profit_value,stop_loss_value,slippage_bps,status,buy_transaction_signature,sell_transaction_signature,error_message,created_at,updated_at,amount_base_token_received,amount_quote_token_received,amount_quote_token_sold,price_per_quote_token_buy,price_per_quote_token_sell,exit_reason,pnl_value,roi_percentage,buy_price_impact_percentage,amount_base_token_spent,base_token_mint,sell_price_impact_percentage,buy_transaction_at,sell_transaction_at,amount_quote_token_to_sell,source}", "rowfilter": null } ]

@grdsdev
Copy link
Contributor

grdsdev commented Sep 26, 2024

Thanks for reporting this issue @blockfer-rp

I just push a PR with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants