Uploaded image for project: 'Couchbase Python Client Library'
  1. Couchbase Python Client Library
  2. PYCBC-878

Tx stuff seems to have broken imports recently

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 3.0.0-beta.3
    • 3.0.0
    • library
    • None
    • 1

    Description

      The following seems like it should work:

      from couchbase_core.cluster import PasswordAuthenticator
      from couchbase.cluster import ClusterOptions
      from txcouchbase.cluster import TxCluster
      from twisted.internet import reactor
       
       
      def cb(resp):
          for r in resp.rows():
              print(r)
       
       
      cluster = TxCluster.connect('couchbase://10.143.194.101',
                                  ClusterOptions(PasswordAuthenticator('Administrator', 'password')))
      b = cluster.bucket('beer-sample')
      resp = b.view_query("beer", "brewery_beers", limit=10)
      resp.add_callback(cb)
       
      # shutdown reactor after 10 seconds
      reactor.callLater(10, reactor.stop)
      reactor.run()

      However, I now get:

      Traceback (most recent call last):
        File "txminimal.py", line 1, in <module>
          from couchbase_core.cluster import PasswordAuthenticator
        File "/Users/davidkelly/projects/gerrit/couchbase-python-client/couchbase_core/cluster.py", line 20, in <module>
          from .client import Client
        File "/Users/davidkelly/projects/gerrit/couchbase-python-client/couchbase_core/client.py", line 5, in <module>
          import couchbase.exceptions as E
        File "/Users/davidkelly/projects/gerrit/couchbase-python-client/couchbase/__init__.py", line 3, in <module>
          from .bucket import *
        File "/Users/davidkelly/projects/gerrit/couchbase-python-client/couchbase/bucket.py", line 1, in <module>
          from couchbase.management import CollectionManager, ViewIndexManager
        File "/Users/davidkelly/projects/gerrit/couchbase-python-client/couchbase/management/__init__.py", line 2, in <module>
          from .views import ViewIndexManager
        File "/Users/davidkelly/projects/gerrit/couchbase-python-client/couchbase/management/views.py", line 22, in <module>
          from couchbase_core.client import Client
      ImportError: cannot import name 'Client' from 'couchbase_core.client' (/Users/davidkelly/projects/gerrit/couchbase-python-client/couchbase_core/client.py)
      

      This used to work. I'm guessing that maybe a recent refactor broke this.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          Ellis.Breen Ellis Breen added a comment - - edited

          Looks like an import cycle, due to

          couchbase_core.cluster
          

          importing

          couchbase_core.client
          

          , and then

          couchbase.exceptions

          , which in turn imports

           couchbase.__init__ 

          which in turn imports

          from .bucket import *

          , and then via a chain. of imports

          couchbase_core.client

          again.

          This could be solved by keeping the actual couchbase exceptions in

          couchbase_core.exceptions

          , as lots of stuff in couchbase_core requires them. We can still surface exceptions in couchbase.exceptions via a '

          from couchbase_core.exceptions import *

          Additionally, I think it's probably time to remove the

           'from .xxx import *' 

          in couchbase._init_ as the circular import wouldn't have happened without it, and now the module structure is settled we should require the end user to be more explicit. In fact, in the tests we use couchbase.cluster.PasswordAuthenticator which works fine (as the couchbase._init_ phase has already passed). I think I've updated all documentation to avoid couchbase_core but should raise a ticket for that as well.

           

          Ellis.Breen Ellis Breen added a comment - - edited Looks like an import cycle, due to couchbase_core.cluster importing couchbase_core.client , and then couchbase.exceptions , which in turn imports couchbase.__init__ which in turn imports from .bucket import * , and then via a chain. of imports couchbase_core.client again. This could be solved by keeping the actual couchbase exceptions in couchbase_core.exceptions , as lots of stuff in couchbase_core requires them. We can still surface exceptions in couchbase.exceptions via a ' from couchbase_core.exceptions import * Additionally, I think it's probably time to remove the 'from .xxx import *' in couchbase._ init _ as the circular import wouldn't have happened without it, and now the module structure is settled we should require the end user to be more explicit. In fact, in the tests we use couchbase.cluster.PasswordAuthenticator which works fine (as the couchbase._ init _ phase has already passed). I think I've updated all documentation to avoid couchbase_core but should raise a ticket for that as well.  

          People

            Ellis.Breen Ellis Breen
            david.kelly David Kelly
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty