Occasional AttributeError from Tree.get_file_by_path

Michael Gliwinski Michael.Gliwinski at henderson-group.com
Mon Oct 25 14:50:26 BST 2010


Hello all,

Just wanted to check before submitting bug report.  I'm encountering a strange 
issue in ``Tree.get_file_by_path`` which seems to be triggered by some 
modifications I'm attempting to the bzr-upload plugin.

The main difference is that I'm passing a WorkingTree instance where the 
original code used a RevisionTree, still I can't see why that would make a 
difference.  The code that triggers the problem is:

ignore_file = self.tree.get_file_by_path('.bzrignore-upload')

Where self.tree previously was a RevisionTree instance and now is a 
WorkingTree instance.  Basically ``get_file_by_path`` implementation is AFAICS 
inherited from ``bzrlib.tree.Tree`` and does the following:

return self.get_file(self._inventory.path2id(path), path)

Now the problem is that in some cases (see below) the ``_inventory`` attribute 
seems to be None which ends up with AttributeError.

I can't establish the exact situations when ``_inventory`` is None, at first I 
only noticed it when using bzrlib API from IPython session, then when running 
the command via qrun (QBzr), but now I'm also getting it via normal CLI 
command run (seems to happen when the tree has uncommitted changes, otherwise 
``_inventory`` points to an Inventory instance).

In any case, the following patch seems to fix the issue:


--- tree.py.orig        2010-10-25 14:40:37.847702690 +0100
+++ tree.py     2010-10-25 14:41:06.477710029 +0100
@@ -324,7 +324,7 @@
         raise NotImplementedError(self.get_file_size)
 
     def get_file_by_path(self, path):
-        return self.get_file(self._inventory.path2id(path), path)
+        return self.get_file(self.path2id(path), path)
 
     def iter_files_bytes(self, desired_files):
         """Iterate through file contents.


I can submit this but I'm not really sure here if I'm doing something wrong or 
is this a bug.  (BTW, the tree should be read-locked before 
``get_file_by_path`` is used, not sure if it matters and didn't check that 
thoroughly).

Thanks for any comments,

Michael


-- 
Michael Gliwinski
Henderson Group Information Services
9-11 Hightown Avenue, Newtownabby, BT36 4RT
Phone: 028 9034 3319

**********************************************************************************************
The information in this email is confidential and may be legally privileged.  It is intended solely for the addressee and access to the email by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.
When addressed to our clients, any opinions or advice contained in this e-mail are subject to the terms and conditions expressed  in the governing client engagement leter or contract.
If you have received this email in error please notify support at henderson-group.com

John Henderson (Holdings) Ltd
Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, BT36 4RT.
Registered in Northern Ireland
Registration Number NI010588
Vat No.: 814 6399 12
*********************************************************************************




More information about the bazaar mailing list