Skip to content

Enable API-versioning and allow for both v3 and v4 versions.#7802

Open
ggainey wants to merge 1 commit into
pulp:mainfrom
ggainey:v4_api
Open

Enable API-versioning and allow for both v3 and v4 versions.#7802
ggainey wants to merge 1 commit into
pulp:mainfrom
ggainey:v4_api

Conversation

@ggainey

@ggainey ggainey commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

This is a tech-preview PR, and will only "turn on" if the ENABLE_V4_API is set to True in settings.

It will allow urls for /v3/ and /v4/, and reject other versions.

For urlpatterns registered with a /<str:version>/ slug, views will be called with a version= kwarg.

NOTE: To play this game, plugins will need to insure that all views accept **kwargs first, and then update the patterns in their urls.py to include the version-slug.

See the /status/ view and serializer(s) for an example of how to respond based on the incoming request.

NOTE to implementers: existing tests must pass without changes whether the ENABLE flag is True or False. If that isn't the case - you're doing something wrong.

closes #6462

@ggainey ggainey force-pushed the v4_api branch 2 times, most recently from 75e4f88 to fcdcf5b Compare June 16, 2026 19:29
@ggainey ggainey force-pushed the v4_api branch 3 times, most recently from d38417a to 1d45f72 Compare June 16, 2026 20:05

result = models.JSONField(default=None, null=True, encoder=DjangoJSONEncoder)

version = models.TextField(default=REST_FRAMEWORK.get("DEFAULT_VERSION", "v3"))

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.

Can we call this api_version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"version" as an attribute is "magic" at the DRF level - it's what gets filled in by the content of the <str:version> slug in the urlpattern. I debated on exactly this - but making it "version" means it's filled directly by the incoming **kwargs to the view, naming it anything else means calling it out specifically. I could be convinced of either.

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.

I was just abit afraid that we could be confusing here. And changing a database column name later is a pain.

(Pulp is in the domain for versioning on all levels. Pulp-version, pulp-api-version, repository-version, deb-version, rpm-version, ansible-collection-version, ...)


version = serializers.CharField(
help_text=_("The API-version that was invoked when creating the task."),
default=REST_FRAMEWORK.get("DEFAULT_VERSION", "v3"),

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.

Suggested change
default=REST_FRAMEWORK.get("DEFAULT_VERSION", "v3"),

I don't think we need this, tasks will never be created via this serializer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Possibly so, will dig a bit.

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.

I don't think we need this, tasks will never be created via this serializer.

You would think, but I remember there being some surprising ways and places in which the serializers were getting initialized.

Comment thread pulpcore/app/settings.py Outdated
Comment thread pulpcore/app/contexts.py
_current_user_func = ContextVar("current_user", default=lambda: None)
_current_domain = ContextVar("current_domain", default=None)
x_task_diagnostics_var = ContextVar("x_profile_task")
_current_pulp_version = ContextVar(

@ggainey ggainey Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment: Is this really how we want to "know" what pulp-version we are operating under? Author, please review!

(also - even if we keep this, name needs to be _current_pulp_api_version)

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.

That I kind ow liked. It's non-invasive, yet omnipresent inside the task code.

@ggainey

ggainey commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

RE ENABLE_V4_API : I am going to turn it on in this PR, in order to make sure CI runs clean with it enabled. BEFORE WE MERGE, we will turn it OFF, and let ppl who want to experiment "opt-in" to it, for several releases.

@ggainey ggainey force-pushed the v4_api branch 2 times, most recently from a06b01e to 949527d Compare June 17, 2026 15:55
This is a tech-preview PR, and will only "turn on" if the
ENABLE_V4_API is set to True in settings.

It will allow urls for /v3/ and /v4/, and reject other versions.

For urlpatterns registered with a `/<str:version>/` slug, views
will be called with a `version=` kwarg.

NOTE: To play this game, plugins will need to insure that all
views accept `**kwargs` first, and then update the patterns in their
`urls.py` to include the version-slug.

See the `/status/` view and serializer(s) for an example of
how to respond based on the incoming request.

NOTE to implementers: **existing tests must pass without changes**
whether the ENABLE flag is True or False. If that isn't the case -
you're doing something wrong.

closes pulp#6462
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.

API namespacing

3 participants