benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 113 forks source link

`couchbeam:doc_exists/2` returns the wrong value. #124

Closed iambumblehead closed 9 years ago

iambumblehead commented 9 years ago

couchbeam:doc_exists/2 returns the wrong value.

I encounter this in any recently tagged branch (I recently upgraded from version 1.0.7 [I think] and did not have this problem there). I will try 1.1.6 now and let you know the result.

Of course if I try to create the design doc (again) couchbeam returns an error, {error,conflict}

%% open the design doc, see that it exists.
Url = "http://localhost:5984",
Auth = [{basic_auth,{<<"jumpyday">>,<<"glo9go99!goB">>}}],
Server = couchbeam:server_connection(Url, Auth),
Options = [],
{ok, Db} = couchbeam:open_db(Server, "user-test"),
DocName = <<"_design/testuser">>,
couchbeam:open_doc(Db, DocName).
%% {ok,{[{<<"_id">>,<<"_design/testuser">>},
%%       {<<"_rev">>,<<"1-17d95a6f5b71dff90129febc7dc5fb7b">>},
%%       {<<"language">>,<<"javascript">>},
%%       {<<"views">>,
%%        {[{<<"test">>,
%%           {[{<<"map">>,
%%              <<"function (doc) {\n if (doc.type == \"test\") {\n emi"...>>}]}},
%%          {<<"test2">>,
%%           {[{<<"map">>,
%%              <<"function (doc) {\n if (doc.type == \"test2\") {"...>>}]}},
%%          {<<"user_name">>,
%%           {[{<<"map">>,
%%              <<"function (doc) { if (doc.name) emit(doc."...>>}]}}]}}]}}
%%
%%
%% now try using doc_exists/2 -it returns false :(
couchbeam:doc_exists(Db, DocName).
%% false

I also see this problem using couchbeam:db_exists/2 but am able to use couchbeam:open_or_create_db/2 in the place of db_exists/2. There is no equivalent open_or_create function for design docs.

benoitc commented 9 years ago

on which couchdb version?

On Thu, Jan 1, 2015 at 10:52 PM, iambumblehead notifications@github.com wrote:

couchbeam:doc_exists/2 returns the wrong value.

I encounter this in any recently tagged branch (I recently upgraded from version 1.0.7 [I think] and did not have this problem there).

Of course if I try to create the design doc (again) couchbeam returns an error, {error,conflict}

%% open the design doc, see that it exists.Url = "http://localhost:5984",Auth = [{basic_auth,{<<"jumpyday">>,<<"glo9go99!goB">>}}],Server = couchbeam:server_connection(Url, Auth),Options = [], {ok, Db} = couchbeam:open_db(Server, "user-test"),DocName = <<"_design/testuser">>,couchbeam:open_doc(Db, DocName).%% {ok,{[{<<"_id">>,<<"_design/testuser">>},%% {<<"_rev">>,<<"1-17d95a6f5b71dff90129febc7dc5fb7b">>},%% {<<"language">>,<<"javascript">>},%% {<<"views">>,%% {[{<<"test">>,%% {[{<<"map">>,%% <<"function (doc) {\n if (doc.type == \"test\") {\n emi"...>>}]}},%% {<<"test2">>,%% {[{<<"map">>,%% <<"function (doc) {\n if (doc.type == \"test2\") {"...>>}]}},%% {<<"user_name">>,%% {[{<<"map">>,%% <<"function (doc) { if (doc.name) emit(doc."...>>}]}}]}}]}}%%%%%% now try using doc_exists/2 -it returns false :(couchbeam:doc_exists(Db, DocName).%% false

— Reply to this email directly or view it on GitHub https://github.com/benoitc/couchbeam/issues/124.

iambumblehead commented 9 years ago
$ couchdb -V
couchdb - Apache CouchDB 1.6.0
benoitc commented 9 years ago

I can't reproduce it on latest version of couchbeam:

1> S = couchbeam:server_connection().
{server,<<"http://127.0.0.1:5984">>,[]}
2> application:ensure_all_started(couchbeam).
{ok,[asn1,crypto,public_key,ssl,idna,hackney,couchbeam]}
3> {ok, Db} = couchbeam:open_or_create_db(S, <<"testdb">>).
{ok,{db,{server,<<"http://127.0.0.1:5984">>,[]},
        <<"testdb">>,[]}}
4> couchbeam:save_doc(Db, {[{<<"_id">>, <<"_design/test">>}, {<<"a">>, 1}]}).
{ok,{[{<<"_id">>,<<"_design/test">>},
      {<<"a">>,1},
      {<<"_rev">>,<<"1-23202479633c2b380f79507a776743d5">>}]}}
5> couchbeam:open_doc(Db, <<"_design/test">>).
{ok,{[{<<"_id">>,<<"_design/test">>},
      {<<"_rev">>,<<"1-23202479633c2b380f79507a776743d5">>},
      {<<"a">>,1}]}}
6> couchbeam:doc_exists(Db, <<"_design/test">>).
true
benoitc commented 9 years ago

Did you also upgraded all depedencies?

iambumblehead commented 9 years ago
> application:ensure_all_started(couchbeam).
{ok,[]}

this may be my problem.

I've used rebar to get and build the latest dependencies. couchbeam is version 1.1.3 (I downgraded to avoid this issue: https://github.com/benoitc/couchbeam/issues/122). Update: I updated to 1.1.6 and see the issue there as well.

> Url = "http://localhost:5984",
> Auth = [{basic_auth,{<<"jumpyday">>,<<"glo9go99!goB">>}}],
> Server = couchbeam:server_connection(Url, Auth).
{server,<<"http://localhost:5984">>,
        [{connect_options,[{nodelay,true}]},
         {basic_auth,{<<"jumpyday">>,<<"glo9go99!goB">>}}]}
> couchbeam:server_connection().
{server,<<"http://127.0.0.1:5984">>,
        [{connect_options,[{nodelay,true}]}]}
> application:ensure_all_started(couchbeam).
{ok,[]}
> {ok, DB} = couchbeam:open_or_create_db(Server, <<"testdb">>).
{ok,{db,{server,<<"http://localhost:5984">>,
                [{connect_options,[{nodelay,true}]},
                 {basic_auth,{<<"jumpyday">>,<<"glo9go99!goB">>}}]},
        <<"testdb">>,
        [{connect_options,[{nodelay,true}]},
         {basic_auth,{<<"jumpyday">>,<<"glo9go99!goB">>}}]}}
> couchbeam:save_doc(DB, {[{<<"_id">>, <<"_design/test2">>}, {<<"a">>, 1}]}).
{ok,{[{<<"_id">>,<<"_design/test2">>},
      {<<"a">>,1},
      {<<"_rev">>,<<"1-23202479633c2b380f79507a776743d5">>}]}}
> couchbeam:open_doc(DB, <<"_design/test2">>).
{ok,{[{<<"_id">>,<<"_design/test2">>},
      {<<"_rev">>,<<"1-23202479633c2b380f79507a776743d5">>},
      {<<"a">>,1}]}}
> couchbeam:doc_exists(DB, <<"_design/test2">>).
false
benoitc commented 9 years ago

hem could you make sue you start with the dependencies in the path? Something like erl -pa ebin -pa deps/*/ebin ? I am not sure how it could work without it though..

iambumblehead commented 9 years ago

I've been starting the shell with this command

$ erl -sname sgani -pa ebin debs/*/ebin -config app
benoitc commented 9 years ago

it should be -pa ebin -pa deps/*/ebin, note the double -pa. Hope it helps. So far I can't reproduce it there.

benoitc commented 9 years ago

@iambumblehead did it solves your issue?

benoitc commented 9 years ago

no feedback since, closing the issue. Feel free to comment if the problem still happen.