Skip to contentSkip to conversation

data_smart: Avoid exceptions for non string data

PATCH In review Richard Purdie 2 participants 3 messages Feb 22, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 data_smart: Avoid exceptions for non string data

File "scripts/lib/checklayer/__init__.py", line 49, in _get_layer_collections
ldata.expandVarref('LAYERDIR')
File "build/bitbake/lib/bb/data_smart.py", line 1007, in expandVarref
if referrervalue and ref in referrervalue:
TypeError: argument of type 'bool' is not iterable

We inject True values as an internal sentinel to the datastore, fix this codepath to handle it.

---
 lib/bb/data_smart.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/data_smart.py +1 -1
index e7047d79ca..8d3825f398 100644
@@ -1004,7 +1004,7 @@ class DataSmart(MutableMapping):
         value = self.getVar(variable, False)
         for key in keys:
             referrervalue = self.getVar(key, False)
-            if referrervalue and ref in referrervalue:
+            if referrervalue and isinstance(referrervalue, str) and ref in referrervalue:
                 self.setVar(key, referrervalue.replace(ref, value))
 
     def localkeys(self):
Signature · 1 line
2.32.0
#1 lore raw

Hi Richard,

Quoted 19 lines · Richard Purdie

File "scripts/lib/checklayer/__init__.py", line 49, in _get_layer_collections
ldata.expandVarref('LAYERDIR')
File "build/bitbake/lib/bb/data_smart.py", line 1007, in expandVarref
if referrervalue and ref in referrervalue:
TypeError: argument of type 'bool' is not iterable

We inject True values as an internal sentinel to the datastore, fix this codepath to handle it.

---
  lib/bb/data_smart.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/data_smart.py +0 -0
index e7047d79ca..8d3825f398 100644

lib/bb/data_smart.py class DataSmart(MutableMapping): · line 1007

Quoted 5 lines
lib/bb/data_smart.py +1 -1
@@ -1004,7 +1004,7 @@ class DataSmart(MutableMapping):
          value = self.getVar(variable, False)
          for key in keys:
              referrervalue = self.getVar(key, False)
-            if referrervalue and ref in referrervalue:
+            if referrervalue and isinstance(referrervalue, str) and ref in referrervalue:

I assume we can remove the referrervalue check? If it was about protecting from None value, isinstance() will return False. If it was about '' string.. it was never needed in the first place since it's ref in '' which would always return false (provided ref is never '' too, but that was not covered by the current condition anyways).

Otherwise... can't we just have referrervalue = self.getVar(key, False) or '' ? so that it's always a string?

Cheers,
Quentin

#2 lore raw
Quoted 17 lines · Quentin Schulz

Hi Richard,

Quoted 14 lines · Richard Purdie

File "scripts/lib/checklayer/__init__.py", line 49, in _get_layer_collections
ldata.expandVarref('LAYERDIR')
File "build/bitbake/lib/bb/data_smart.py", line 1007, in expandVarref
if referrervalue and ref in referrervalue:
TypeError: argument of type 'bool' is not iterable

We inject True values as an internal sentinel to the datastore, fix this codepath to handle it.

---
  lib/bb/data_smart.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines

lib/bb/data_smart.py class DataSmart(MutableMapping): · line 1007

Quoted 10 lines
lib/bb/data_smart.py +1 -1
index e7047d79ca..8d3825f398 100644
@@ -1004,7 +1004,7 @@ class DataSmart(MutableMapping):
          value = self.getVar(variable, False)
          for key in keys:
              referrervalue = self.getVar(key, False)
-            if referrervalue and ref in referrervalue:
+            if referrervalue and isinstance(referrervalue, str) and ref in referrervalue:

I assume we can remove the referrervalue check? If it was about protecting from None value, isinstance() will return False. If it was about '' string.. it was never needed in the first place since it's ref in '' which would always return false (provided ref is never '' too, but that was not covered by the current condition anyways).

True, we could have done that.

Quoted 2 lines

Otherwise... can't we just have referrervalue = self.getVar(key, False) or '' ? so that it's always a string?

No, since getVar could return a bool or int.

Cheers,

Richard