Git Product home page Git Product logo

Comments (5)

levchik avatar levchik commented on May 18, 2024

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.

dasv avatar dasv commented on May 18, 2024

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.

levchik avatar levchik commented on May 18, 2024

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.

dasv avatar dasv commented on May 18, 2024

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.

levchik avatar levchik commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.