Skip to content

Commit

Permalink
528 flatten no longer returns None values
Browse files Browse the repository at this point in the history
  • Loading branch information
adp-atea committed Oct 25, 2023
1 parent f50ea24 commit 4c493ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions spinta/utils/nestedstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ def flatten(value, sep='.', array_sep='[]'):
if value is None:
for k, vals in lists:
for v in vals:
yield from flatten(v, sep)
if v is not None:
yield from flatten(v, sep)

elif lists:
keys, lists = zip(*lists)
for vals in itertools.product(*lists):
val = {
sep.join(k): v
for k, v in zip(keys, vals)
for k, v in zip(keys, vals) if v is not None
}
val.update(value)
yield from flatten(val, sep)
Expand All @@ -34,9 +35,10 @@ def _flatten(value, sep, array_sep, key=()):
data = {}
lists = []
for k, v in value.items():
v, more = _flatten(v, sep, array_sep, key + (k,))
data.update(v or {})
lists += more
if v is not None:
v, more = _flatten(v, sep, array_sep, key + (k,))
data.update(v or {})
lists += more
return data, lists

elif isinstance(value, (list, Iterator)):
Expand All @@ -45,12 +47,12 @@ def _flatten(value, sep, array_sep, key=()):
key = list(key)
key[-1] = f'{key[-1]}{array_sep}'
key = tuple(key)
return None, [(key, value)]
return None, [(key, value)] if value is not None else []
else:
return None, []

else:
return {sep.join(key): value}, []
return {sep.join(key): value} if value is not None else {}, []


def build_select_tree(select: List[str]) -> Dict[str, Set[Optional[str]]]:
Expand Down
1 change: 1 addition & 0 deletions spinta/utils/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class SQLiteDialect_spinta_sqlite(SQLiteDialect_pysqlite):
driver = 'spinta_sqlite'
supports_statement_cache = True

@classmethod
def dbapi(cls):
Expand Down

0 comments on commit 4c493ec

Please sign in to comment.