-
Notifications
You must be signed in to change notification settings - Fork 215
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
[BUG] Revision Id is in Responsemodel #648
Comments
Hi! Thank you for the catch. I'll check and fix this in the next bug-fixing session this or next week |
This bug was fixed in #669. Please try |
Hmm for me it still says "revision_id": null I checked out fix/august_2023, that should be the correct branch, right? |
Yes, this is the correct branch. I'll doublecheck it |
I reproduced it. When you use response model (or You can fix this either using import motor.motor_asyncio
from beanie import Document, init_beanie
from fastapi import FastAPI
class TestDocument(Document):
somefield: int = 1
app = FastAPI()
@app.on_event("startup")
async def app_init():
client = motor.motor_asyncio.AsyncIOMotorClient("mongodb://beanie:beanie@localhost:27017")
await init_beanie(
client.beanie_db,
document_models=[TestDocument],
)
@app.post("/test/", response_model_exclude={"revision_id"})
async def some_post_endpoint(test: TestDocument) -> TestDocument:
return await test.save() or just not set response model: import motor.motor_asyncio
from beanie import Document, init_beanie
from fastapi import FastAPI
class TestDocument(Document):
somefield: int = 1
app = FastAPI()
@app.on_event("startup")
async def app_init():
client = motor.motor_asyncio.AsyncIOMotorClient("mongodb://beanie:beanie@localhost:27017")
await init_beanie(
client.beanie_db,
document_models=[TestDocument],
)
@app.post("/test/")
async def some_post_endpoint(test: TestDocument):
return await test.save() |
Okay, makes sense. Thanks for the in depth explanation :) |
This issue is stale because it has been open 30 days with no activity. |
This issue was closed because it has been stalled for 14 days with no activity. |
Hi @roman-right! I was wondering if this case is consider as a bug as well, by default is returning from motor.motor_asyncio import AsyncIOMotorClient
from beanie import Document, init_beanie
import os
from dotenv import load_dotenv
load_dotenv()
class ArticleDoc(Document):
title: str
class Settings:
name = 'article_entries'
async def init(conn_str: str = "mongodb://user:pass@host:27017"):
client = AsyncIOMotorClient(os.environ.get("MONGODB_CONN_STR", conn_str))
await init_beanie(
database=client[os.environ.get("MONGODB_NAME", "dev")],
document_models=[ArticleDoc]
)
async def main() -> None:
await init()
articles = await ArticleDoc.find().to_list()
print(articles[0]) # id=ObjectId('64cc9cb2d2523f3c6a397ff2') revision_id=None title='Taiwan sales surge in July'
if __name__ == '__main__':
import asyncio
asyncio.run(main()) |
Describe the Bug
revision_id is included in genetated Responsebody, it is not the same as the generated Example Value, which does not include revision_id.
To Reproduce
Expected behavior
The response shouldnt include "revision_id": null
Additional context
fastapi version used: 0.101.0
The text was updated successfully, but these errors were encountered: