Skip to content

Commit

Permalink
Merge pull request #205 from CAVEconnectome/fix_refererence_table_qry
Browse files Browse the repository at this point in the history
correct field names when columns collide
  • Loading branch information
ceesem authored Aug 7, 2024
2 parents 7965ac2 + c8025d9 commit 804de9b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions caveclient/tools/table_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,21 @@ def make_class_vals(
return class_vals


def rename_fields(filter_dict, cls):
rename_map = {}
for a in attrs.fields(type(cls)):
if a.metadata.get("original_name"):
rename_map[a.name] = a.metadata["original_name"]
fix_dict = {}
for tn in filter_dict:
for k in filter_dict[tn]:
if k in rename_map:
fix_dict[tn] = k
for tn, k in fix_dict.items():
filter_dict[tn][rename_map[k]] = filter_dict[tn].pop(k)
return filter_dict


def make_kwargs_mixin(client, is_view=False, live_compatible=True):
class BaseQueryKwargs(object):
def __attrs_post_init__(self):
Expand All @@ -387,6 +402,8 @@ def __attrs_post_init__(self):
)
for tn in tables
}
filter_equal_dict = rename_fields(filter_equal_dict, self)

filter_in_dict = {
tn: filter_empty(
attrs.asdict(
Expand All @@ -400,6 +417,8 @@ def __attrs_post_init__(self):
)
for tn in tables
}
filter_in_dict = rename_fields(filter_in_dict, self)

spatial_dict = {
tn: update_spatial_dict(
attrs.asdict(
Expand All @@ -412,6 +431,7 @@ def __attrs_post_init__(self):
)
for tn in tables
}
spatial_dict = rename_fields(spatial_dict, self)

self.filter_kwargs_live = {
"filter_equal_dict": replace_empty_with_none(
Expand Down

0 comments on commit 804de9b

Please sign in to comment.