nats-io / nats.py

Python3 client for NATS
https://nats-io.github.io/nats.py/
Apache License 2.0
874 stars 182 forks source link

KeyValue.watchall include_history ignored #584

Open skewty opened 2 months ago

skewty commented 2 months ago

Observed behavior

history values are enumerated regardless of boolean value passed

Expected behavior

history values are enumerated only when boolean value is true

Server and client version

nats-py 2.8.0 nats-server 2.10.17

Host environment

No response

Steps to reproduce

import asyncio
import logging

import nats
from nats.js.api import KeyValueConfig, StorageType
from nats.js.errors import BucketNotFoundError

async def run() -> None:
    nc = await nats.connect("tls://demo.nats.io:4443")
    jc = nc.jetstream()
    try:
        kv = await jc.key_value('nats_test')
    except BucketNotFoundError:
        kv = await jc.create_key_value(KeyValueConfig('nats_test', storage=StorageType.FILE))
    await kv.put('test_key', b'test')
    logger.info("Watching config started")
    include_history = True
    try:
        while True:
            async for entry in await kv.watchall(include_history=include_history, inactive_threshold=2**10):
                logger.info(f"Change for {entry}")
            include_history = False
    except BaseException:
        logger.exception("Error watching config")
        raise
    finally:
        logger.info("Watching config exiting")

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('nats.testing')
asyncio.run(run())

Also see #580 and #583

skewty commented 1 week ago

Is there any way to watch a value in the current code base? I tried watch(">") and watchall() and neither stay running. They exit shortly after giving me the value from history. Kinda renders the feature useless