Comments (5)
Hi, @dasv
That is because internally we pass to list
method kwargs as dict to pymongo
as a first argument (which is sort=sort_desc
in your example). So when we call pymongo
's list
method to get the cursor we pass it {"sort": [('transmit_time', -1)]}
which is not correct filter, neither correct ordering. We don't do any stripping based on the names of keyword arguments passed to list
.
To solve this problem, we released 0.1.15 version which adds new keyword argument _sort
to thelist
method of mongodb models. In this version we also separated the optional packages from the main dependency, which is FastAPI
. For example, to install this library with mongodb, ujson and pytz as it was before, you should do now: pip install fastapi_contrib[mongo,ujson,pytz]==0.1.15
.
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
from fastapi_contrib.
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...
from fastapi_contrib.
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.
from fastapi_contrib.
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.
You're doing great work! Thank you!
from fastapi_contrib.
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).
from fastapi_contrib.
Related Issues (20)
- Issue with updating a document HOT 3
- Minor error in README code sample of limit-offset pagination HOT 2
- Why is the version of FastAPI fixed in the install_requires? HOT 2
- How to save data in Mongo? HOT 3
- has_required_permisions typo or bypass of naming conflict? HOT 3
- Importing models as a package and creating indexes HOT 1
- Allow overriding settings from fastAPI app HOT 2
- Support docker secrets in configuration HOT 1
- Add Changelog HOT 4
- Why Serializer do not output "_id" field? HOT 1
- fastapi version 0.65.1 compatibility
- Project Status
- ModuleNotFoundError: No module named 'fastapi_contrib' HOT 2
- How to mock or override PermissionsDependency
- Add Python 3.8 support HOT 1
- Where can I find info on "MongoDB indices verification on startup of the app" feature? HOT 2
- Firestore DB Support HOT 3
- Add Support for FastAPI latest version HOT 2
- consider using configurator for settings store HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi_contrib.