Skip to content

Database Splitting + Convert --> Crash : Exception thrown: Call failed with status code 400 (Bad Request) #186

@cfeltz34

Description

@cfeltz34

I have an object in CouchDB with a lot en fields.
I just want to get light objects.

Is ok if I execute this command :

var couchDocuments = couchDatabase.Take(TAKE_LIMIT).Select(d => d.Id, d => d.Rev).ToList();
--> couchdb request parameters is : 
"{\"limit\":1000,\"fields\":[\"_id\",\"_rev\"],\"selector\": {\"split_discriminator\":\"ExampleDataCouchDB\"}}"

But my object is not correctly typed

If I execute this command :

var couchDocuments2 = couchDatabase.Take(TAKE_LIMIT).Convert<TCouchDocument, TypedCouchDocumentBase>().ToList();
--> couchdb request parameters is : 
"{\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}}\"typeMessage\",\"errorMessage\"],\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}}"

A comma is missing --> Crash : Exception thrown: 'Flurl.Http.FlurlHttpException' in System.Private.CoreLib.dll: 'Call failed with status code 400 (Bad Request): POST http://127.0.0.1:5984/example/_find'

If I execute this command :

var couchDocuments3 = couchDatabase.Take(TAKE_LIMIT).Convert<TCouchDocument, CouchDocumentBase>().ToList();
--> couchdb request parameters is : 
"{\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}],\"selector\":{\"split_discriminator\":\"ExampleDataCouchDB\"}}"

No fields have been selected --> Crash : Exception thrown: 'Flurl.Http.FlurlHttpException' in System.Private.CoreLib.dll: 'Call failed with status code 400 (Bad Request): POST http://127.0.0.1:5984/example/_find'

Remark :
In VisitConvertMethod method, why you have this condition : ".Where(p => p.DeclaringType != typeof(CouchDocument))" ?
How can I get an object containing only the Id and the revision (Rev) ?

Remark 2 : For both "Convert" case, Take(1000) is not added on request

    public class TypedCouchDocumentBase : CouchDocumentBase, IDto, EntityWithKeyAsString
    {
        virtual public string typeMessage { get; set; }
        virtual public string errorMessage { get; set; }

        public TypedCouchDocumentBase() { 
        }
    }

    public class CouchDocumentBase : CouchDocument
    {
        public CouchDocumentBase() { 
        }
    }
using System;
using System.Threading.Tasks;
using CouchDB.Driver;
using CouchDB.Driver.Options;
using ExampleApi.Models;
using ExampleApi.ModelsCouchDB;
using Microsoft.Extensions.Logging;

namespace ExampleApi.CouchDB
{
    public class CouchDBContext : CouchContext
    {
        public string DatabaseName = "example";

        public CouchDatabase<ExampleDataCouchDB> ExampleDatas { get; set; }
        public CouchDatabase<DesignDocument> ExampleDesign { get; set; }

        protected override void OnDatabaseCreating(CouchDatabaseBuilder databaseBuilder)
        {
            databaseBuilder.Document<ExampleDataCouchDB>().ToDatabase(this.DatabaseName);
            databaseBuilder.Document<DesignDocument>().ToDatabase(this.DatabaseName);
        }
    }
}

Metadata

Metadata

Labels

invalidThis doesn't seem right

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions