Skip to content

Conversation

@lmeyerov
Copy link
Contributor

@lmeyerov lmeyerov commented Dec 29, 2025

Summary

  • add collections validator with strict/autofix behavior and GFQL wire normalization
  • expose collections API with validate/warn and plot-time URL param validation
  • add collections tests and clarify plan template location
  • move collections helpers to graphistry/collections.py and introduce typed models in graphistry/models/collections.py

Testing

  • python -m pytest graphistry/tests/test_collections.py graphistry/tests/test_dataset_id_invalidation.py
  • ./bin/lint.sh
  • ./bin/mypy.sh

show_collections: Optional[bool] = None,
collections_global_node_color: Optional[str] = None,
collections_global_edge_color: Optional[str] = None,
encode: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the interest of simplifying, would it be difficult to detect pre-encoded strings?

Copy link
Contributor Author

@lmeyerov lmeyerov Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this surprised me: the reason it's like this is bc the base REST api takes AABBCC instead of ~css colors like we started to do elsewhere i believe (js color(xyz) normalizes to rgba('...'), handling '#AABBCC', 'silver', etc)

so maybe fix is to ship better colors in REST, and then this upgrades to that?

Copy link
Contributor

@mj3cheun mj3cheun Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think thats a great idea to ship better colours in REST will add that to the list

i was talking about the encode: bool = True, though, which is If True, JSON-minify and URL-encode collections. Use False for pre-encoded strings.

i was thinking we could just detect pre-encoded strings (which i assume are URL encoded and can be detected by attempting a parse). then we can remove this parameter

validate: ValidationParam = 'autofix',
warn: bool = True
) -> List[Dict[str, Any]]:
validate_mode, warn = normalize_validation_params(validate, warn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this seems to already be called everywhere that uses normalize_collections, can either remove this extra call here or remove the normalize_validation_params everywhere else

Comment on lines +70 to +73
if isinstance(collections, list):
return _coerce_collection_list(collections, validate_mode, warn)
if isinstance(collections, dict):
return _coerce_collection_list(collections, validate_mode, warn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: would just get rid of the _coerce_collection_list function and put the contents in here, would get rid of checking is list is dict etc twice and make easier to read

Comment on lines +321 to +322
if validate_mode == 'autofix':
collection_type = str(collection_type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if collection_type was not already a string, im not sure that just typecasting it is going to produce a valid type string given this string must be either set or intersection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually nevermind, just saw the if collection_type not in ('set', 'intersection'): below, im thinking maybe combine this check with the check below, if collection_type is not string its all but guaranteed to fail and hit continue in the section below

@mj3cheun
Copy link
Contributor

general comment, validate_mode = 'autofix' seems more likely to produce invalid output and/or result in a collection getting skipped than otherwise. to me its biggest value is typecasting stuff like id=1 to id="1" etc. not sure how much value there is in making it explicit, maybe we just have warn true/false and otherwise handle things silently?

@lmeyerov
Copy link
Contributor Author

hmm, if they do something like g.plot(validate_mode='autofix'), what do we want to happen , or not happen, w/ collections?

that was mostly added b/c people keep having dirty data that fails arrow conversion and rather seeing it load vs fixing their data/cfg

return raw
return raw

return _normalize_ops_list(_extract_ops_value(gfql_ops))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel this could be simplified by just feeding the GFQL into graphistry.compute.chain and seeing if it parses properly rather than setting up stuff here to determine if GFQL is valid or not

Comment on lines +264 to +271
if expr_type != 'intersection':
_issue(
'Intersection expr type must be "intersection"',
{'index': entry_index, 'value': expr_type},
validate_mode,
warn
)
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is only called if type is intersection, so this if statement will never return true

@mj3cheun
Copy link
Contributor

mj3cheun commented Jan 12, 2026

@lmeyerov regarding general comment above: im thinking maybe instead of validate we call it strict with "true" or "false" where strict true will throw errors and false will pass over non-compliant collections

autofix sorta implies to me that we are "correcting" the data when invalid but we arent really i think? more just passing it over if there are any mistakes

if we feel we need to type cast we might want to just do it anyway strict true or not

@lmeyerov
Copy link
Contributor Author

lmeyerov commented Jan 12, 2026

the issue with strict true/false is that's closer to what we had before, and users were complaining that they just wanted it to 'work', hence autofix (coerce++). validate=true/false is closer to what you're thinking, while 'autofix' (coerce) is "it'll run, but may not be what you want, but you said wanted soemthing that runs"

We therefore have leeway in what autofix does --- we just need to warn (if warn=auto/true), and do what. So the q is... what should it do wrt diff collections errors, if strong opinions about any params in any direction?

My default intuition is probably:

  • drop collections with invalid gfql
  • colors: random-but-deterministic? or neutral grey / transparent? (default black looks buggy)
  • others: ??? disable / see if there's default values ?

@mj3cheun
Copy link
Contributor

mj3cheun commented Jan 12, 2026

agree with that, i think we do the 3 bullets listed if strict (or whatever we want to call it) is false and its almost what we are doing right now. theres only 1 point i would make about the current implementation

  • instead of just trying to typecast stuff (which a lot of the time doesnt work), i would prefer we do default values or in the case of colours, random colours

in summary its only the approach i think might need to change, not the intention

EDIT: if we do the above it actually gets closer to a true autofix than what it was before, so i dont have an issue with the name anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants