Skip to content

Commit

Permalink
Remove version_name
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimbuddy committed Nov 13, 2024
1 parent ad03d9d commit ef8cce6
Show file tree
Hide file tree
Showing 25 changed files with 144 additions and 268 deletions.
9 changes: 2 additions & 7 deletions airflow/api_connexion/endpoints/dag_source_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@
def get_dag_source(
*,
dag_id: str,
version_name: str | None = None,
version_number: int | None = None,
session: Session = NEW_SESSION,
) -> Response:
"""Get source code from DagCode."""
dag_version = DagVersion.get_version(dag_id, version_number, version_name, session=session)
dag_version = DagVersion.get_version(dag_id, version_number, session=session)
if not dag_version:
raise NotFound(
f"The source code of the DAG {dag_id}, version {version_name} and version_number {version_number} was not found"
)
raise NotFound(f"The source code of the DAG {dag_id}, version_number {version_number} was not found")
path = dag_version.dag_code.fileloc
dag_ids = session.scalars(select(DagModel.dag_id).where(DagModel.fileloc == path)).all()
requests: Sequence[IsAuthorizedDagRequest] = [
Expand All @@ -69,7 +66,6 @@ def get_dag_source(
raise PermissionDenied()
dag_source = dag_version.dag_code.source_code
version_number = dag_version.version_number
version_name = dag_version.version_name

return_type = request.accept_mimetypes.best_match(["text/plain", "application/json"])
if return_type == "text/plain":
Expand All @@ -79,7 +75,6 @@ def get_dag_source(
{
"content": dag_source,
"dag_id": dag_id,
"version_name": version_name,
"version_number": version_number,
}
)
Expand Down
8 changes: 0 additions & 8 deletions airflow/api_connexion/openapi/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,6 @@ paths:
operationId: get_dag_source
tags: [DAG]
parameters:
- $ref: "#/components/parameters/VersionName"
- $ref: "#/components/parameters/VersionNumber"
responses:
"200":
Expand Down Expand Up @@ -5787,13 +5786,6 @@ components:
description: |
List of field for return.
VersionName:
in: query
name: version_name
schema:
type: string
description: |
The name of the version.
VersionNumber:
in: query
name: version_number
Expand Down
1 change: 0 additions & 1 deletion airflow/api_connexion/schemas/dag_source_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class DagSourceSchema(Schema):

content = fields.String(dump_only=True)
dag_id = fields.String(dump_only=True)
version_name = fields.String(dump_only=True)
version_number = fields.Integer(dump_only=True)


Expand Down
1 change: 0 additions & 1 deletion airflow/api_fastapi/core_api/datamodels/dag_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ class DAGSourceResponse(BaseModel):

content: str | None
dag_id: str
version_name: str | None
version_number: int | None
14 changes: 0 additions & 14 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1448,14 +1448,6 @@ paths:
schema:
type: string
title: Dag Id
- name: version_name
in: query
required: false
schema:
anyOf:
- type: string
- type: 'null'
title: Version Name
- name: version_number
in: query
required: false
Expand Down Expand Up @@ -4173,11 +4165,6 @@ components:
dag_id:
type: string
title: Dag Id
version_name:
anyOf:
- type: string
- type: 'null'
title: Version Name
version_number:
anyOf:
- type: integer
Expand All @@ -4187,7 +4174,6 @@ components:
required:
- content
- dag_id
- version_name
- version_number
title: DAGSourceResponse
description: DAG Source serializer for responses.
Expand Down
4 changes: 1 addition & 3 deletions airflow/api_fastapi/core_api/routes/public/dag_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ async def get_dag_source(

dag_source = dag_version.dag_code.source_code
version_number = dag_version.version_number
dag_source_model = DAGSourceResponse(
dag_id=dag_id, content=dag_source, version_number=version_number
)
dag_source_model = DAGSourceResponse(dag_id=dag_id, content=dag_source, version_number=version_number)

if accept.startswith(mime_type_text):
return Response(dag_source_model.content, media_type=mime_type_text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def upgrade():
"dag_version",
sa.Column("id", UUIDType(binary=False), nullable=False),
sa.Column("version_number", sa.Integer(), nullable=False),
sa.Column("version_name", StringID()),
sa.Column("dag_id", StringID(), nullable=False),
sa.Column("created_at", UtcDateTime(), nullable=False, default=timezone.utcnow),
sa.ForeignKeyConstraint(
Expand Down
1 change: 0 additions & 1 deletion airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ class DAG(TaskSDKDag, LoggingMixin):
**Warning**: A fail stop dag can only have tasks with the default trigger rule ("all_success").
An exception will be thrown if any task in a fail stop dag has a non default trigger rule.
:param dag_display_name: The display name of the DAG which appears on the UI.
:param version_name: The version name to use in storing the dag to the DB.
"""

partial: bool = False
Expand Down
13 changes: 1 addition & 12 deletions airflow/models/dag_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class DagVersion(Base):
__tablename__ = "dag_version"
id = Column(UUIDType(binary=False), primary_key=True, default=uuid6.uuid7)
version_number = Column(Integer, nullable=False, default=1)
version_name = Column(StringID())
dag_id = Column(StringID(), ForeignKey("dag.dag_id", ondelete="CASCADE"), nullable=False)
dag_model = relationship("DagModel", back_populates="dag_versions")
dag_code = relationship(
Expand Down Expand Up @@ -78,7 +77,6 @@ def write_dag(
cls,
*,
dag_id: str,
version_name: str | None = None,
version_number: int = 1,
session: Session = NEW_SESSION,
) -> DagVersion:
Expand All @@ -88,7 +86,6 @@ def write_dag(
Checks if a version of the DAG exists and increments the version number if it does.
:param dag_id: The DAG ID.
:param version_name: The version name.
:param version_number: The version number.
:param session: The database session.
:return: The DagVersion object.
Expand All @@ -102,7 +99,6 @@ def write_dag(
dag_version = DagVersion(
dag_id=dag_id,
version_number=version_number,
version_name=version_name,
)
log.debug("Writing DagVersion %s to the DB", dag_version)
session.add(dag_version)
Expand Down Expand Up @@ -137,7 +133,6 @@ def get_version(
cls,
dag_id: str,
version_number: int | None = None,
version_name: str | None = None,
*,
session: Session = NEW_SESSION,
) -> DagVersion | None:
Expand All @@ -146,22 +141,16 @@ def get_version(
:param dag_id: The DAG ID.
:param version_number: The version number.
:param version_name: The version name.
:param session: The database session.
:return: The version of the DAG or None if not found.
"""
version_select_obj = select(cls).where(cls.dag_id == dag_id)
if version_number:
version_select_obj = version_select_obj.where(cls.version_number == version_number)
if version_name:
version_select_obj = version_select_obj.where(cls.version_name == version_name)

return session.scalar(version_select_obj.order_by(cls.id.desc()).limit(1))

@property
def version(self) -> str:
"""A human-friendly representation of the version."""
name = f"{self.version_number}"
if self.version_name:
name = f"{self.version_name}-{self.version_number}"
return name
return f"{self.dag_id}-{self.version_number}"
1 change: 0 additions & 1 deletion airflow/models/serialized_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def write_dag(
log.debug("Serialized DAG (%s) is unchanged. Skipping writing to DB", dag.dag_id)
return False
dagv = DagVersion.write_dag(
version_name=dag.version_name,
dag_id=dag.dag_id,
session=session,
)
Expand Down
1 change: 0 additions & 1 deletion airflow/serialization/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
},
"dag_display_name": { "type" : "string"},
"description": { "type" : "string"},
"version_name": {"type": "string"},
"_concurrency": { "type" : "number"},
"max_active_tasks": { "type" : "number"},
"max_active_runs": { "type" : "number"},
Expand Down
4 changes: 1 addition & 3 deletions airflow/ui/openapi-gen/queries/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,16 @@ export const UseDagSourceServiceGetDagSourceKeyFn = (
{
accept,
dagId,
versionName,
versionNumber,
}: {
accept?: string;
dagId: string;
versionName?: string;
versionNumber?: number;
},
queryKey?: Array<unknown>,
) => [
useDagSourceServiceGetDagSourceKey,
...(queryKey ?? [{ accept, dagId, versionName, versionNumber }]),
...(queryKey ?? [{ accept, dagId, versionNumber }]),
];
export type EventLogServiceGetEventLogDefaultResponse = Awaited<
ReturnType<typeof EventLogService.getEventLog>
Expand Down
11 changes: 1 addition & 10 deletions airflow/ui/openapi-gen/queries/prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,6 @@ export const prefetchUseDagRunServiceGetDagRun = (
* Get source code using file token.
* @param data The data for the request.
* @param data.dagId
* @param data.versionName
* @param data.versionNumber
* @param data.accept
* @returns DAGSourceResponse Successful Response
Expand All @@ -466,29 +465,21 @@ export const prefetchUseDagSourceServiceGetDagSource = (
{
accept,
dagId,
versionName,
versionNumber,
}: {
accept?: string;
dagId: string;
versionName?: string;
versionNumber?: number;
},
) =>
queryClient.prefetchQuery({
queryKey: Common.UseDagSourceServiceGetDagSourceKeyFn({
accept,
dagId,
versionName,
versionNumber,
}),
queryFn: () =>
DagSourceService.getDagSource({
accept,
dagId,
versionName,
versionNumber,
}),
DagSourceService.getDagSource({ accept, dagId, versionNumber }),
});
/**
* Get Event Log
Expand Down
12 changes: 2 additions & 10 deletions airflow/ui/openapi-gen/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ export const useDagRunServiceGetDagRun = <
* Get source code using file token.
* @param data The data for the request.
* @param data.dagId
* @param data.versionName
* @param data.versionNumber
* @param data.accept
* @returns DAGSourceResponse Successful Response
Expand All @@ -582,29 +581,22 @@ export const useDagSourceServiceGetDagSource = <
{
accept,
dagId,
versionName,
versionNumber,
}: {
accept?: string;
dagId: string;
versionName?: string;
versionNumber?: number;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useQuery<TData, TError>({
queryKey: Common.UseDagSourceServiceGetDagSourceKeyFn(
{ accept, dagId, versionName, versionNumber },
{ accept, dagId, versionNumber },
queryKey,
),
queryFn: () =>
DagSourceService.getDagSource({
accept,
dagId,
versionName,
versionNumber,
}) as TData,
DagSourceService.getDagSource({ accept, dagId, versionNumber }) as TData,
...options,
});
/**
Expand Down
12 changes: 2 additions & 10 deletions airflow/ui/openapi-gen/queries/suspense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,6 @@ export const useDagRunServiceGetDagRunSuspense = <
* Get source code using file token.
* @param data The data for the request.
* @param data.dagId
* @param data.versionName
* @param data.versionNumber
* @param data.accept
* @returns DAGSourceResponse Successful Response
Expand All @@ -567,29 +566,22 @@ export const useDagSourceServiceGetDagSourceSuspense = <
{
accept,
dagId,
versionName,
versionNumber,
}: {
accept?: string;
dagId: string;
versionName?: string;
versionNumber?: number;
},
queryKey?: TQueryKey,
options?: Omit<UseQueryOptions<TData, TError>, "queryKey" | "queryFn">,
) =>
useSuspenseQuery<TData, TError>({
queryKey: Common.UseDagSourceServiceGetDagSourceKeyFn(
{ accept, dagId, versionName, versionNumber },
{ accept, dagId, versionNumber },
queryKey,
),
queryFn: () =>
DagSourceService.getDagSource({
accept,
dagId,
versionName,
versionNumber,
}) as TData,
DagSourceService.getDagSource({ accept, dagId, versionNumber }) as TData,
...options,
});
/**
Expand Down
13 changes: 1 addition & 12 deletions airflow/ui/openapi-gen/requests/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1343,17 +1343,6 @@ export const $DAGSourceResponse = {
type: "string",
title: "Dag Id",
},
version_name: {
anyOf: [
{
type: "string",
},
{
type: "null",
},
],
title: "Version Name",
},
version_number: {
anyOf: [
{
Expand All @@ -1367,7 +1356,7 @@ export const $DAGSourceResponse = {
},
},
type: "object",
required: ["content", "dag_id", "version_name", "version_number"],
required: ["content", "dag_id", "version_number"],
title: "DAGSourceResponse",
description: "DAG Source serializer for responses.",
} as const;
Expand Down
2 changes: 0 additions & 2 deletions airflow/ui/openapi-gen/requests/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,6 @@ export class DagSourceService {
* Get source code using file token.
* @param data The data for the request.
* @param data.dagId
* @param data.versionName
* @param data.versionNumber
* @param data.accept
* @returns DAGSourceResponse Successful Response
Expand All @@ -923,7 +922,6 @@ export class DagSourceService {
accept: data.accept,
},
query: {
version_name: data.versionName,
version_number: data.versionNumber,
},
errors: {
Expand Down
Loading

0 comments on commit ef8cce6

Please sign in to comment.