Commits

rothniets  committed 8f4059a

ironing out some kinks

  • Participants
  • Parent commits 50f0636

Comments (0)

Files changed (1)

File beets/library.py

             self.flexattrs[key] = FixedDict(flexattrns[key])
         
         #treat flexattrs values as they would come from the database
-        if values['flexkeys'] and values['flexvalues'] and values['flexns']:
+        k = values.keys()
+        if 'flexkeys' in k and 'flexvalues' in k and 'flexns' in k:
             flexkeys = values['flexkeys'].split(',')
             flexvalues = values['flexvalues'].split(',')
             flexns = values['flexns'].split(',')
+            log.debug('flexkeys: %s - flexvals: %s - flexns: %s', 
+                      flexkeys, flexvalues, flexns)
             for i, key in enumerate(flexkeys):
                 namespace = flexns[i]
                 if namespace not in self.flexattrs:
                 value = flexvalues[i]
                 if not self.flexattrs.has_key(namespace):
                     self.flexattrs[namespace] = {}
-                    self.flexattrs[flexns[i]][key] = flexvalues[i]
+                self.flexattrs[flexns[i]][key] = flexvalues[i]                    
 
     def _clear_dirty(self):
         self.dirty = {}
         clause_parts = []
         subvals = []
         for subq in self.subqueries:
-            if subq.namespace:
+            if hasattr(subq, 'namespace') and subq.namespace:
                 #it's a flex attr query, initiate -ugly hack- mode
                 entity = subq.entity
                 clauses = flexclause_parts
             WHERE {1})
             '''
             fclause = flexorclause.format(entity, fclause)
-        return clause+' '+joiner+' '+fclause, subvals+flexsubvals
+        if clause and fclause:
+            clause = clause+' '+joiner+' '+fclause
+        elif clause:
+            clause = clause
+        elif fclause:
+            clause = fclause
+        return clause, subvals+flexsubvals
 
     # Regular expression for _parse_query_part, below.
     _pq_regex = re.compile(
             #flexible attributes
             flexins = '''INSERT INTO item_attributes 
                       (entity_id, key, value, namespace) 
-                      VALUES (?,?,?);'''
+                      VALUES (?,?,?,?);'''
             for ns,attrs in item.flexattrs.iteritems():
                 for key in attrs.dirty:
                     tx.mutate(flexins, (store_id, key, attrs[key], ns))
             # "Add" the artist to the query.
             query = AndQuery((query, MatchQuery('albumartist', artist)))
         where, subvals = query.clause()
-        sql = "SELECT * FROM albums " + \
+        sql = "SELECT * FROM unified_albums " + \
               "WHERE " + where + \
               " ORDER BY %s, album" % \
                 _orelse("albumartist_sort", "albumartist")