Conflicting Positional Arguments Using @app.page() Functionality
还没有人认领这个 Issue。
评估
调研方向
The traceback points to dispatch in faust/web/views.py (around line 118), which calls the handler as method(request, **kwargs), and to how @app.page wraps a plain function as a view method. Start by checking how the wrapped function's signature is bound there. Run a minimal @app.page('/data/') handler that takes only request and returns web.json. Done when the GET returns the JSON body without the takes 1 positional argument but 2 were given TypeError.
由索引模型根据 Issue 内容生成。
描述
Steps to reproduce
The actual topic, agent, table should not matter. The issue is with the web request. I only included the agent, table, etc in case something about the agent and page decorators conflicted or interacted with each other unexpectedly.
import faust
from faust import web
import pandas as pd
from datetime import timezone
import json
# Faust app setup
app = faust.App('realtime_processor', broker='kafka://localhost:9092')
topic_name = 'first_test_topic'
kafka_topic = app.topic(topic_name, value_type=bytes)
processed_data_table = app.Table('processed_data', default=float, partitions=1)
# A simple model for our items to enforce a schema
class DataItem(faust.Record, validation=True):
timestamp: str
value: float
@app.agent(kafka_topic)
async def process(stream):
async for message in stream:
data = message
if 'Items' in data:
for entry in data['Items']:
if 'Items' in entry:
for item in entry['Items']:
# timestamp = pd.to_datetime(item['Timestamp']).replace(tzinfo=timezone.utc).timestamp()
timestamp = item['Timestamp']
value = item['Value']
# Update faust table
processed_data_table[timestamp] = value
# Print the entire table
# print("Current state of the table:")
# for key, value in processed_data_table.items():
# print(f"{key}: {value}")
# print("-" * 40) # Just a separator for readability
@app.page('/data/')
async def fetch_first_test_topic(request: web.Request) -> web.Response:
# Extract query parameters for time range or other filters if needed
# For example:
# start_time = request.query['start_time']
# end_time = request.query['end_time']
# Convert table data to list of DataItem objects
# data_list = [DataItem(timestamp=key, value=value).to_representation()
# for key, value in processed_data_table.items()]
# # Convert list of DataItem objects to JSON
# json_data = json.dumps(data_list)
json_data={'hello':'world'}
# Return JSON response
return web.json(json_data)
Script I used to reach this endpoint:
import pandas as pd
import requests
response = requests.get('http://127.0.0.1:6066/data/')
print(response.text)
data = response.json() # This should be the JSON array of objects
print(data)
Expected behavior
I was expecting from the print statement of the get request to be
{'hello':'world'}
Actual behavior
I got errors on both the get request side and the faust side, suggesting the that get request communicated with the faust app, but for some reason there is an error with positional arguments, despite none being defined.
Full traceback
On the faust app side
[2023-11-08 16:23:29,783] [2282037] [ERROR] Error handling request
Traceback (most recent call last):
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
resp = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/site-packages/faust/web/drivers/aiohttp.py", line 246, in _dispatch
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/site-packages/faust/web/views.py", line 102, in __call__
return await self.dispatch(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/site-packages/faust/web/views.py", line 118, in dispatch
response = await method(cast(Request, request), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fetch_first_test_topic() takes 1 positional argument but 2 were given
On the GET request side
500 Internal Server Error
Server got itself in trouble
Traceback (most recent call last):
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/json/decoder.py", line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/ksuden/source/Tps-PricePrediction/data_works/data_streaming/faust/api_query.py", line 6, in <module>
data = response.json() # This should be the JSON array of objects
^^^^^^^^^^^^^^^
File "/home/ksuden/anaconda3/envs/py311/lib/python3.11/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Extra data: line 1 column 5 (char 4)
Versions
- Python version: 3.11
- Faust version: 0.10.16
- Operating system: Linux
- Kafka version: 2.0.2
- RocksDB version (if applicable)
- 主要语言
- Python
- 星标
- 1.9k
- 派生
- 205
- 平均合并
- 2 小时 2 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
faust-streaming/faust 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 86/100
faust-streaming/faust#804 ·
-
scripts/install script forces use of ./venv virtualenv, impossible to use with virtualenvwrapper未关闭
难度 1/5 1 小时以内 新手友好度 62/100
faust-streaming/faust#28 · 1 条评论 ·
-
[BUG] SASL PLAINTEXT producer initialization fails : missing sasl_plain_username/password可能已有人在做 @wbarnha 于 56 天前认领。 未关闭
faust-streaming/faust#794 · 2 条评论 · 1 个 reaction · 已指派 2 人 ·
-
难度 4/5 3-5 天 新手友好度 18/100
faust-streaming/faust#670 ·
-
难度 4/5 3-5 天 新手友好度 18/100
faust-streaming/faust#666 ·
查看 faust-streaming/faust 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
OpenFreeEnergy/openfe#2371 ·
维护者通常 2 天内回复
-
HMDB's smiles file writes "None" for metabolites with an empty <smiles/> (file not currently used)未关闭
难度 2/5 1-3 小时 新手友好度 80/100
NCATSTranslator/Babel#1269 ·
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 80/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 64/100
bcgov/nr-hydrometric-rating-curve#443 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100