Extract duplicated list type handling logic into reusable helper#1559
Merged
neiljbrookes merged 2 commits intobugfix/ml-anomaly-job-import-sparse-statefrom Dec 16, 2025
Merged
Conversation
…function - Created EnsureTypedList helper in typeutils package - Replaced three instances of duplicated logic for handling untyped zero-value lists - Removed unused strings import from resource.go - All three instances (CategorizationFilters, Influencers, CustomRules) now use the centralized helper Co-authored-by: neiljbrookes <851324+neiljbrookes@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix anomaly detection job import/refresh mismatch issue
Extract duplicated list type handling logic into reusable helper
Dec 16, 2025
neiljbrookes
approved these changes
Dec 16, 2025
0185df6
into
bugfix/ml-anomaly-job-import-sparse-state
76 checks passed
neiljbrookes
added a commit
that referenced
this pull request
Dec 17, 2025
* fix(ml): make anomaly_detection_job import resilient Fixes terraform import/refresh failures for elasticstack_elasticsearch_ml_anomaly_detection_job by keeping ImportState sparse (id/job_id only) and allowing analysis_config to be null during import before Read populates it. Also ensures empty nested lists in analysis_config (e.g. categorization_filters/influencers/custom_rules) are always typed to avoid DynamicPseudoType conversion errors. AI assistance: This change was implemented with the help of an AI coding assistant (Cursor + GPT). * Update internal/elasticsearch/ml/anomaly_detection_job/resource.go Co-authored-by: Toby Brain <toby.brain@elastic.co> * Remove unused import in anomaly_detection_job resource file * Add ImportState testing for anomaly_detection_job acceptance tests This update introduces ImportState testing for the elasticstack_elasticsearch_ml_anomaly_detection_job resource, ensuring that the job can be imported correctly with the necessary configuration variables. The test verifies the import functionality and enhances the robustness of the acceptance tests. * Extract duplicated list type handling logic into reusable helper (#1559) * Initial plan * Refactor: extract duplicated list type handling into reusable helper function - Created EnsureTypedList helper in typeutils package - Replaced three instances of duplicated logic for handling untyped zero-value lists - Removed unused strings import from resource.go - All three instances (CategorizationFilters, Influencers, CustomRules) now use the centralized helper Co-authored-by: neiljbrookes <851324+neiljbrookes@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: neiljbrookes <851324+neiljbrookes@users.noreply.github.com> * Update CHANGELOG.md to include a fix for `elasticstack_elasticsearch_ml_anomaly_detection_job` import, enhancing resilience to sparse state values. --------- Co-authored-by: Toby Brain <toby.brain@elastic.co> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: neiljbrookes <851324+neiljbrookes@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses code review feedback to eliminate duplicated logic for handling untyped zero-value lists that appear during import operations. The pattern was repeated identically in three locations within the anomaly detection job model conversion.
Changes
Added
EnsureTypedListhelper ininternal/utils/typeutils/list.goRefactored duplicate logic in
models_tf.gofor:Removed unused import from
resource.goBefore
After
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.