-
Notifications
You must be signed in to change notification settings - Fork 303
Fixes #38542 - Delay params for import_uploads action #11430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideExtracts dynamic repository import parameters from the controller into a dedicated Apipie DSL concern loaded on initialization, and modernizes the content_type parameter to use a callable enum for up‐to‐date labels. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c3cc7e5
to
654dbca
Compare
654dbca
to
497dc04
Compare
repo_wrap_params = RootRepository.attribute_names + generic_repo_wrap_params | ||
|
||
wrap_parameters :repository, :include => repo_wrap_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not necessary, but seems nicer to delegate atribute_names
call to Rails instead of calling it explicitly here. I'd love to get rid of calling database related stuff during initialization time.
@@ -493,7 +491,7 @@ def upload_content | |||
param :async, :bool, desc: N_("Do not wait for the ImportUpload action to finish. Default: false") | |||
param 'publish_repository', :bool, :desc => N_("Whether or not to regenerate the repository on disk. Default: true") | |||
param 'sync_capsule', :bool, :desc => N_("Whether or not to sync an external capsule after upload. Default: true") | |||
param :content_type, RepositoryTypeManager.uploadable_content_types(false).map(&:label), :required => false, :desc => N_("content type ('deb', 'docker_manifest', 'file', 'ostree_ref', 'rpm', 'srpm')") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We introduced callable_enum
in Foreman some time ago just for such cases: theforeman/foreman#10494
@@ -0,0 +1,3 @@ | |||
Rails.application.config.after_initialize do | |||
Katello::Api::V2::RepositoriesController.include Katello::Concerns::Api::V2::DynamicParams::Repositories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done now it different places, e.g. in to_prepare
block in engine.rb
. This is just for readability? and a default place for similar cases.
module Repositories | ||
extend ::Apipie::DSL::Concern | ||
|
||
lazy_update_api(:import_uploads) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lazy_update_api
doesn't exist in apipie-rails
yet, the PR is open: Apipie/apipie-rails#955
::Katello::RepositoryTypeManager.generic_repository_types.each_pair do |_, repo_type| | ||
repo_type.import_attributes.each do |import_attribute| | ||
param import_attribute.api_param, import_attribute.type, | ||
:desc => N_(import_attribute.description) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already there, but N_()
doesn't work with variables so
:desc => N_(import_attribute.description) | |
:desc => import_attribute.description |
param import_attribute.api_param, import_attribute.type, | ||
:desc => N_(import_attribute.description) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking out loud now. Would it be possible to extend the DSL with a method so you still keep the API definition in one place? For example lazy_api
(or better naming):
end | |
lazy_api do | |
Katello::RepositoryTypeManager.generic_repository_types.each_value do |repo_type| | |
repo_type.import_attributes.each do |import_attribute| | |
param import_attribute.api_param, import_attribute.type, desc: import_attribute.description | |
end | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that, but this would introduce a new pattern (not that this is bad, but this new method will be available for every controller which use apipie mixin potentially introducing more conflicts).
Current PR to apipie-rails rather extends existing pattern. Personally I don't care, but it's up to maintainers/reviewers/users to decide.
What are the changes introduced in this pull request?
This PR tries to remove pain points of touching database during initialization times. There are might be other places, so maintainers, please point me to them, so we can get rid of them.
Considerations taken when implementing this change?
We kinda have a bad habit of calling the DB during initialization time, which leads to weird and hard to debug errors. The errors may or may not appear, making them even uglier.
I've tried to find a way how to workaround it and it seems moving such code into
after_initialize
orto_prepare
blocks doesn't always work. Rails doesn't guarantee when the DB is ready. We could establish the connection manually somewhere, but it seems like an even worse solution.Given that, I think we need to treat each case differently depending on what's the root of the problem.
What are the testing steps for this pull request?
I don't think we cover params with tests, needs manual API docs verification.
Summary by Sourcery
Consolidate dynamic import parameter definitions for the import_uploads action into an Apipie concern loaded after initialization, and switch the content_type parameter to use a callable_enum for dynamically generated values.
Enhancements: