Skip to content

[contextgen] Honor parameterization in generator instance, expose parameters to serialize#1983

Merged
amc-corey-cox merged 6 commits into
linkml:mainfrom
sneakers-the-rat:contextgen-model-params
Jan 29, 2026
Merged

[contextgen] Honor parameterization in generator instance, expose parameters to serialize#1983
amc-corey-cox merged 6 commits into
linkml:mainfrom
sneakers-the-rat:contextgen-model-params

Conversation

@sneakers-the-rat

Copy link
Copy Markdown
Collaborator

Builds on #1982

Noticed that the contextgen advertises parameters in its dataclass fields that it then ignores during serialization.

If those fields exist, they should do something!

set all args to default None and use instance attributes as defaults instead of method args as defaults - parameters can be set in the instance body, but overridden when calling serialize

@sneakers-the-rat

Copy link
Copy Markdown
Collaborator Author

looks like the failing tests are choices to make - the old behavior didn't honor the defaults set in the instance, so the tests confirm that. if we want that to be the case (ie. when you set a value in the generator instance it is actually used) then we need to change those tests probably. since this PR is unsolicited i'll wait until someone confirms this is the desired behavior before fixing

@amc-corey-cox

Copy link
Copy Markdown
Contributor

Hey @sneakers-the-rat sorry I misunderstood the comments above. It sounds like this may still be worthwhile, so I'm going to leave it open... and possibly revisit this myself. As you mentioned, we have had some PRs piling up. That is something I'm trying to improve and some of that is reducing our cognitive tax in having so many dead PRs open.

With that said, I don't want to lose meaningful work so I'll see what we can do about this one. Also, if you feel like anything is sitting please ping me on it and I'll try to move it along.

@sneakers-the-rat

Copy link
Copy Markdown
Collaborator Author

This one is relatively simple - should I update the test cases to reflect the working state? Or should we remove those parameters?

@amc-corey-cox

Copy link
Copy Markdown
Contributor

@sneakers-the-rat I'm sorry my attention was pulled elsewhere for a while and I just got back to this one. Yes, this looks simple and I'd like to get it in. Can you resolve the conflict and I'll try to get it merged right away? It looks like a simple matter of accepting your change but I don't want to end up doing something foolish so I defer to you.

@codecov

codecov Bot commented Oct 30, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.20%. Comparing base (1c309d6) to head (c051386).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1983      +/-   ##
==========================================
+ Coverage   79.54%   83.20%   +3.66%     
==========================================
  Files         155      155              
  Lines       17545    17567      +22     
  Branches     3582     3589       +7     
==========================================
+ Hits        13956    14617     +661     
+ Misses       2834     2149     -685     
- Partials      755      801      +46     
Flag Coverage Δ
linkml 79.56% <100.00%> (+0.03%) ⬆️
runtime 79.56% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sneakers-the-rat

sneakers-the-rat commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator Author

alright, so maybe unsurprisingly, fixing this unmasked some other bugs.

So since the previous behavior was to incorrectly ignore the instance attributes on the context genera, and the library had come to expect it to be incorrect, when the contextgen started using its instance attributes a lot of the tests, particularly the snapshot tests which are not specific and always require changes whenver the code changes at all, we had to fix a few tests to explicitly specify the things they were expecting of the context generator.

Additionally, the non-context json-ld generator's CLI was broken, where not passing --context results in an empty tuple() rather than None, so the cli behavior differed from the programmatic behavior, and that was reflected in the tests. so in order to make that possible to pass without just weakening the tests,

  • i fixed that problem and cast it to None when not passed
  • added the ability to pass kwargs to the context generator from the cli and via the serialize method.
  • adjusted tests that expected the previous incorrect contextgen behavior to use that.

@amc-corey-cox amc-corey-cox force-pushed the contextgen-model-params branch from b2132b8 to c051386 Compare January 29, 2026 21:32

@amc-corey-cox amc-corey-cox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me.

@amc-corey-cox amc-corey-cox merged commit 6971be8 into linkml:main Jan 29, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants