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

Embedded resource updated __last_cursor, return wrong total in _meta #1268

Closed
b3g00d opened this issue May 16, 2019 · 4 comments

Comments

Projects
None yet
2 participants
@b3g00d
Copy link

commented May 16, 2019

Expected Behavior

When I get normally without embedded
the total in HATEOAS return correct total belong to this code
https://github.com/pyeve/eve/tree/c4e894aeaadd982c6449329b00fcb050e6c70152/eve/io/mongo/mongo.py#L274

    "_links": {                                                                      
        "parent": {                                                                                                                                                         
            "href": "/",                                                        
            "title": "home"                         
        },                                                                                                                                                                  
        "self": {                                                                                                                                                                 
            "href": "tickets?max_results=5",                               
            "title": "tickets"                                                                                                                                              
        }                                                            
    },                                                              
    "_meta": {                                                                                                                                                              
        "max_results": 5,                                                                                                                                                         
        "page": 1,                                                                                                                                                                                       
        "total": 5                                                              
    } 

I want the same thing with embedded={"user": 1}

Actual Behavior

But when embedded
https://github.com/pyeve/eve/tree/c4e894aeaadd982c6449329b00fcb050e6c70152/eve/methods/common.py#L896
will update __last_target
https://github.com/pyeve/eve/tree/c4e894aeaadd982c6449329b00fcb050e6c70152/eve/io/mongo/mongo.py#L261
then the return of total https://github.com/pyeve/eve/tree/c4e894aeaadd982c6449329b00fcb050e6c70152/eve/io/mongo/mongo.py#L274
will be wrong

    "_links": {                                                                                                                                                                   
        "parent": {                                      
            "href": "/",                                                                                                                                                    
            "title": "home"                                        
        },                                                          
        "self": {                                                                                                                                                           
            "href": "tickets?max_results=5",                                                                                                                                      
            "title": "tickets"                                  
        }                                        
    },                                                             
    "_meta": {                            
        "max_results": 5,       
        "page": 1,                                     
        "total": 1                                               
    } 

the spec will be like this {'$or': [{'_id': ObjectId('5cc02d98bf42f8740738916d')}]} after cursor.next()

And I tried to fix by using cursor.count() instead app.data.last_documents_count, but I'm not sure that going to work without a test.

Environment

  • Python version: 3.6.7
  • Eve version: 0.9

@b3g00d b3g00d changed the title Embedded resource updated __last_cursor Embedded resource updated __last_cursor, return wrong total in _meta May 16, 2019

nicolaiarocci added a commit that referenced this issue May 17, 2019

@nicolaiarocci

This comment has been minimized.

Copy link
Member

commented May 17, 2019

could you please try if the issue is solved by installing from branch issue_#1268?

@b3g00d

This comment has been minimized.

Copy link
Author

commented May 17, 2019

@nicolaiarocci After reviewing your commit and tested by calling API, the result is correct.

@nicolaiarocci nicolaiarocci added this to the 0.9.1 milestone May 20, 2019

nicolaiarocci added a commit that referenced this issue May 20, 2019

@nicolaiarocci

This comment has been minimized.

Copy link
Member

commented May 20, 2019

erm... actually I took a different approach, which is coherent with changes introduced because of #1271. Can you please pull from https://github.com/pyeve/eve/tree/issue_%231268 and try again?

@b3g00d

This comment has been minimized.

Copy link
Author

commented May 22, 2019

@nicolaiarocci Look good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.