Skip to content

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

@b3g00d

Description

@b3g00d

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions