Skip to content
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

count property value is wrong for GET methods #156

Open
AlexandreKavalerski opened this issue Nov 16, 2023 · 1 comment
Open

count property value is wrong for GET methods #156

AlexandreKavalerski opened this issue Nov 16, 2023 · 1 comment

Comments

@AlexandreKavalerski
Copy link

When page limit is applied, the value for count property in get method is wrong. It returns the count of all records instead of the current page length.

Refer to methods:

  • paginate in safrs/jsonapi_formatting.py
  • get in safrs/jsonapi.py

count is being calculated based on initial length of object_query, but it should consider instances length after applying pagination.

@thomaxxl
Copy link
Owner

thomaxxl commented Nov 17, 2023

Hi,

This is by design: if you want the number of items returned you can use the length of data[].
You can change this behaviour by overriding _s_count , eg:

class BaseModel(SAFRSBase, db.Model):
    __abstract__ = True
    def _s_count():
        return 100

class User(BaseModel):
    """
    description: My User description
    """

    __tablename__ = "Users"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    email = db.Column(db.String)

I added the meta.total to be compatible with a particular frontend client but it's the same value as meta.count. I may make this more configurable in the future though because it's not too obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants