bzr init-repos --development-wt5-rich-root gives: "AttributeError: 'module' object has no attribute 'WorkingTreeFormat4'"

Bug #328135 reported by Wesley J. Landaker
2
Affects Status Importance Assigned to Milestone
Bazaar
Fix Released
High
John A Meinel

Bug Description

With the latest bzr.dev, I can't seem to use --development-wt5-rich-root:

$ bzr init-repo --development-wt5-rich-root .
bzr: ERROR: exceptions.AttributeError: 'module' object has no attribute 'WorkingTreeFormat4'

Traceback (most recent call last):
  File "/home/wjlanda/lib/python/bzrlib/commands.py", line 893, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/home/wjlanda/lib/python/bzrlib/commands.py", line 839, in run_bzr
    ret = run(*run_argv)
  File "/home/wjlanda/lib/python/bzrlib/commands.py", line 512, in run_argv_aliases
    args, opts = parse_args(self, argv, alias_argv)
  File "/home/wjlanda/lib/python/bzrlib/commands.py", line 591, in parse_args
    options, args = parser.parse_args(args)
  File "/usr/lib/python2.5/optparse.py", line 1385, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/usr/lib/python2.5/optparse.py", line 1425, in _process_args
    self._process_long_opt(rargs, values)
  File "/usr/lib/python2.5/optparse.py", line 1500, in _process_long_opt
    option.process(opt, value, values, self)
  File "/usr/lib/python2.5/optparse.py", line 782, in process
    self.action, self.dest, opt, value, values, parser)
  File "/usr/lib/python2.5/optparse.py", line 802, in take_action
    self.callback(self, opt, value, parser, *args, **kwargs)
  File "/home/wjlanda/lib/python/bzrlib/option.py", line 393, in cb
    v = self.type(cb_value)
  File "/home/wjlanda/lib/python/bzrlib/option.py", line 307, in convert
    return self.converter(value)
  File "/home/wjlanda/lib/python/bzrlib/builtins.py", line 1557, in <lambda>
    converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
  File "/home/wjlanda/lib/python/bzrlib/bzrdir.py", line 2819, in make_bzrdir
    return self.get(key)()
  File "/home/wjlanda/lib/python/bzrlib/bzrdir.py", line 2767, in helper
    bd.workingtree_format = _load(tree_format)
  File "/home/wjlanda/lib/python/bzrlib/bzrdir.py", line 2752, in _load
    [factory_name])
  File "/home/wjlanda/lib/python/bzrlib/workingtree_4.py", line 96, in <module>
    from bzrlib.workingtree import WorkingTree, WorkingTree3, WorkingTreeFormat3
  File "/home/wjlanda/lib/python/bzrlib/workingtree.py", line 2957, in <module>
    __default_format = WorkingTreeFormat4()
  File "/home/wjlanda/lib/python/bzrlib/lazy_import.py", line 122, in __call__
    obj = _replace()
  File "/home/wjlanda/lib/python/bzrlib/lazy_import.py", line 89, in _replace
    obj = factory(self, scope, name)
  File "/home/wjlanda/lib/python/bzrlib/lazy_import.py", line 193, in _import
    return getattr(module, member)
AttributeError: 'module' object has no attribute 'WorkingTreeFormat4'

bzr 1.13dev on python 2.5.2 (linux2)
arguments: ['/home/wjlanda/bin/bzr', 'init-repo', '--development-wt5-rich-root', '.']
encoding: 'UTF-8', fsenc: 'UTF-8', lang: 'en_US.UTF-8'
plugins:
  bisect /home/wjlanda/.bazaar/plugins/bisect [1.1.0.pre.0]
  bookmarks /home/wjlanda/.bazaar/plugins/bookmarks [unknown]
  bzrtools /home/wjlanda/lib/python/bzrlib/plugins/bzrtools [1.12]
  cvsps_import /usr/lib/python2.5/site-packages/bzrlib/plugins/cvsps_import [unknown]
  diffstat /home/wjlanda/.bazaar/plugins/diffstat [0.2]
  extcommand /home/wjlanda/.bazaar/plugins/extcommand [unknown]
  gtk /home/wjlanda/.bazaar/plugins/gtk [0.96.0.dev.1]
  interactive /home/wjlanda/.bazaar/plugins/interactive [1.2]
  launchpad /home/wjlanda/lib/python/bzrlib/plugins/launchpad [unknown]
  netrc_credential_store /home/wjlanda/lib/python/bzrlib/plugins/netrc_credential_store [unknown]
  qbzr /home/wjlanda/.bazaar/plugins/qbzr [0.9.8dev]
  rebase /usr/lib/python2.5/site-packages/bzrlib/plugins/rebase [0.4.2]
  search /home/wjlanda/.bazaar/plugins/search [1.7dev]
  stats /usr/lib/python2.5/site-packages/bzrlib/plugins/stats [unknown]
  svn /home/wjlanda/lib/python/bzrlib/plugins/svn [0.5.1dev]
  upload /usr/lib/python2.5/site-packages/bzrlib/plugins/upload [0.1]
  xmloutput /home/wjlanda/.bazaar/plugins/xmloutput [0.8.2]
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.

Actually, the same thing happens with --developement-wt5 whether or not I use --rich-root, and also happens with a regular bzr init.

Related branches

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

That's really weird and I can't reproduce it. All the following work for me using bzr.dev r4000:

  bzr init-repo --development-wt5-rich-root .
  bzr init-repo --development-wt5 .
  bzr init-repo .

Trying with init instead of init-repo seems fine as well.

I wonder if there's any chance of some corrupted .pyc or pyo files? Can you try deleting those and seeing if the issue still exists?

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

Talden has also reported this problem on the mailing list. I wonder if it's a Windows vs Linux thing wrt lazy imports?

Revision history for this message
Wesley J. Landaker (wjl) wrote :

FWIW, I'm running Linux, and am using a bzr.dev that I update regularly.

I suppose corrupted .pyc files are possible. I will try completely clearing my install and reinstalling. I'm not at my development system at the moment, so I'll report back tomorrow.

Revision history for this message
Wesley J. Landaker (wjl) wrote :

Okay, I just tried nuking my entire bzr install -- including all plugins -- and reinstalling bzr.dev r4000 from scratch. I still get this same error.

Running Debian lenny, python2.5, bzr.dev r4000.

Revision history for this message
Alexander Belchenko (bialix) wrote :

The same on Windows.

Revision history for this message
Alexander Belchenko (bialix) wrote :

Ian what is your Python version?

Revision history for this message
John A Meinel (jameinel) wrote :

I'll put together a fix for this for 1.12, as it does make it imposible to init-repo or init with this flag.

Changed in bzr:
assignee: nobody → jameinel
importance: Undecided → High
milestone: none → 1.12
status: New → In Progress
Revision history for this message
John A Meinel (jameinel) wrote :

Looking closely, it turns out that this is an import loop problem with just doing:

  import bzrlib.workingtree_4

You have to "import bzrlib.workingtree" before you "import bzrlib.workingtree_4"

This is because inside of workingtree it imports workingtree_4. In theory it does this in a lazy way, such that it doesn't actually trigger until the end of workingtree.py (When __default_format is set.)

However, if you *start* by importing workingtree_4.py, then it loads and is half-initialized, when it then tries to import workingtree.py, which then wraps around to import workingtree_4 again, and gets the half-loaded module.

If you do "import bzrlib.workingtree", it changes things. Such that it loads all of workingtree.py gets things initialized, and *then* auto-imports workingtree_4, but by that time the "from bzrlib.workingtree import XXX" already has workingtree.py loaded.

The reason we haven't seen this before is because the other formats technically do the "wrong" thing:

format_registry.register_metadir('1.9-rich-root',
    'bzrlib.repofmt.pack_repo.RepositoryFormatKnitPack6RichRoot',
    help='A variant of 1.9 that supports rich-root data '
         '(needed for bzr-svn).',
    branch_format='bzrlib.branch.BzrBranchFormat7',
    tree_format='bzrlib.workingtree.WorkingTreeFormat4',
    )

^- Notice that it uses the variable in "bzrlib.workingtree". Which has been imported from bzrlib.workingtree_4. Technically, you shouldn't use that syntax. Obviously in practice it is necessary.

So the simple fix, which I'll submit, is to just change the lazy registrations to do the same. I don't see any easy way to get "import bzrlib.workingtree_4" to work cleanly, without a lot of work to make the registration of WTFormat4 lazy. (Especially difficult as it is the "default" format.)

Changed in bzr:
status: In Progress → Fix Committed
Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

This has now landed in the 1.12 branch. It will land in bzr.dev shortly after 1.12 is released and Martin merges the 1.12 tweaks across, i.e. hopefully in the next 24 hours.

Vincent Ladeuil (vila)
Changed in bzr:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.