Skip to content

Fix bugs with caching and format validation when importing files#204

Merged
Fivell merged 2 commits intoactiveadmin-plugins:masterfrom
Skumring:Fix-bugs-with-caching-and-format-validation-when-importing-files
Apr 8, 2026
Merged

Fix bugs with caching and format validation when importing files#204
Fivell merged 2 commits intoactiveadmin-plugins:masterfrom
Skumring:Fix-bugs-with-caching-and-format-validation-when-importing-files

Conversation

@Skumring
Copy link
Copy Markdown
Contributor

@Skumring Skumring commented Jan 20, 2026

Bug 1: File caching issue - form reuses cached file after validation error

Short Description

When submitting the import form after a validation error, the system reuses the previously cached file instead of showing the "no file" error when no file is selected. This causes confusion and potential unintended data imports.

For more details, see #205


Bug 2: File format validation occurs after encoding when using auto force_encoding

Short Description

When force_encoding: :auto is configured, the file encoding process runs BEFORE file format validation. This causes the system to attempt encoding operations on invalid file formats (e.g., .txt files), leading to unnecessary processing overhead and incorrect error handling flow.

For more details, see #206


Local tests result

bundle exec rspec spec/import_spec.rb  
Screenshot 2026-01-29 at 19 11 21

@Skumring Skumring marked this pull request as draft January 21, 2026 10:53
@Skumring Skumring force-pushed the Fix-bugs-with-caching-and-format-validation-when-importing-files branch from c689419 to 00c6464 Compare January 29, 2026 17:37
@Skumring Skumring marked this pull request as ready for review January 29, 2026 17:51
validate :file_contents_present, if: ->(me) { me.file.present? }

before_validation :unzip_file, if: ->(me) { me.archive? && me.allow_archive? }
before_validation :encode_file, if: ->(me) { me.force_encoding? && me.file.present? }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Skumring i think after_validation will run even if there are validation errors, lets improve it with

 after_validation :encode_file, if: ->(me) { me.errors.empty? && me.force_encoding? &&
   me.file.present? }

@Skumring Skumring force-pushed the Fix-bugs-with-caching-and-format-validation-when-importing-files branch from 00c6464 to 89a841d Compare April 8, 2026 07:28
@Fivell Fivell self-requested a review April 8, 2026 07:32
@Fivell Fivell merged commit c5f8ffe into activeadmin-plugins:master Apr 8, 2026
34 checks passed
@Fivell Fivell mentioned this pull request Apr 8, 2026
5 tasks
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.

2 participants