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
Passing extra arguments to MongoDBModel.list() #34
Comments
Hi, @dasv That is because internally we pass to To solve this problem, we released 0.1.15 version which adds new keyword argument So, to make your example work, you can just upgrade the version and change your code to the following: @router.get("/")
async def get_packets(limit: int = 100, offset: int = 0):
sort_desc = [('transmit_time', -1)]
packets = await Packet.list(_limit=limit, _offset=offset, _sort=sort_desc)
return packets |
Fantastic! But sadly, it seems that I cannot install it because of the FastAPI version requirements: fastapi_contrib 0.1.14 is compatible with any version of FastAPI >= 0.35.0, but fastapi_contrib 0.1.15 is limited to fastapi <=0.37.0,>=0.35.0. I am using FastAPI 0.42, the latest version. What are the compatibility reasons for this change? Seeing how the arguments are passed, passing **{"$orderby": {"transmit_time": -1}} would work, but the $orderby operator is deprecated for mongo > 3.2... |
The reason for pinning version in such way is that multiple newer versions of FastAPI have different version of Pydantic, which this package heavily relies on, and on that newer version multiple tests are failed. In fact, various of the Pydantic versions (which have changed quite a few times, being a dependency of FastAPI from 0.35.0 to current 0.42.0, they've changed in minor versions and grew rapidly with the FastAPI itself) are breaking this package in different ways. Last time I checked, one of the related changes that broke our code is from FastAPI itself (so it has not so big impact as Pydantic did). I think, now that Pydantic is actually 1.0, we can try and write some compatibility code for the current pinned versions of FastAPI and aim for support of the major version, as well as current latest FastAPI (this should not be a big problem). I guess this is going to be 0.2 of this package after we get Pydantic versions sorted out. There are long going plans for making it to the 1.0 as well and probably there are going to be separate packages of mongo-related stuff, opentracing stuff, and possibly even more. The goal is to figure out what the core should be and give it a clear vision. |
Oh, I see. For the time being, I can downgrade to 0.37 as I was not using many of the new features, just allowing "None" for path parameters, and being able to sort results is much more important. |
Hi @dasv , if you're still interested, I've just released 0.1.16 version of this package with support for the latest FastAPI (0.42.0). |
Description
Hi,
I am trying to get a list of entries from a collection sorted in descending order according to a recorded date (not a creation timestamp, I am not using the timestamped model). Pymongo sort should work passing a sort=[(key, value)] argument, but when I do that, I get back an empty list. Am I doing anything wrong?
What I Did
This is my function. The field transmit_time is a MongoDB date field.
The text was updated successfully, but these errors were encountered: