sahilSENPAII opened a new issue, #74814:
URL: https://github.com/apache/airflow/issues/74814

   ### Under which category would you file this issue?
   
   Airflow Core
   
   ### Apache Airflow version
   
   main (development), commit 5ab698987f. The same code is in 3.3.0, 3.3.1, 
3.3.2 and 3.4.0b1.
   
   ### What happened and how to reproduce it?
   
   `GET /api/v2/assets/events?name_prefix_pattern=~` returns every asset event 
once per asset in the database, and `total_entries` is multiplied by the number 
of assets. The API description documents `~` as matching everything, so this 
should return the same events as having no filter.
   
   ### Steps to reproduce
   
   1. Have two assets with one asset event each (for example, create the events 
with `POST /api/v2/assets/events`).
   2. `GET /api/v2/assets/events` returns 2 events, `total_entries: 2`.
   3. `GET /api/v2/assets/events?name_prefix_pattern=~` returns 4 items (each 
event twice) and `total_entries: 4`.
   
   ### Cause
   
   In `airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py`, 
`get_asset_events` joins `AssetModel` only when a name filter value is truthy:
   
   ```python
   if name_pattern.value or name_prefix_pattern.value:
       base_statement = base_statement.join(AssetModel, AssetEvent.asset_id == 
AssetModel.id)
   ```
   
   For prefix filters, `~` is transformed to `""`, which is falsy, so the join 
is skipped. The prefix filter still applies `AssetModel.name IS NOT NULL`, so 
the query selects `FROM asset_event, asset` without a join condition, a 
cartesian product. This was introduced in #64963.
   
   ### What you think should happen instead?
   
   `name_prefix_pattern=~` should return the same events and `total_entries` as 
no name filter. The join should be added whenever a name filter value is not 
None, rather than when it is truthy.
   
   ### Operating System
   
   macOS
   
   ### Deployment
   
   None
   
   ### Apache Airflow Provider(s)
   
   _No response_
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Official Helm Chart version
   
   Not Applicable
   
   ### Kubernetes Version
   
   _No response_
   
   ### Helm Chart configuration
   
   _No response_
   
   ### Docker Image customizations
   
   _No response_
   
   ### Anything else?
   
   `name_pattern=~` is not affected, because it is transformed to `%`, which is 
truthy, so the join is added.
   
   I have a failing test and a one-line fix ready and will open a PR.
   
   ### Are you willing to submit PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to