Skip to content

Exclude properties in QueryProjection outside constructor#1232

Merged
velo merged 1 commit intomasterfrom
fix/query-projection-included-props
Jun 15, 2025
Merged

Exclude properties in QueryProjection outside constructor#1232
velo merged 1 commit intomasterfrom
fix/query-projection-included-props

Conversation

@IceBlizz6
Copy link
Copy Markdown
Collaborator

This pull request solves the issue that was reported in my original repository earlier this week.
IceBlizz6/querydsl-ksp#9

Currently this code

data class PersonClassConstructorDTO @QueryProjection constructor(
    val id: Int,
    val name: String,
) {
    var age: Int = 0
}

Becomes

public class QPersonClassConstructorDTO(
    id: Expression<Int>,
    name: Expression<String>,
    age: Expression<Int>,
) : ConstructorExpression<PersonClassConstructorDTO>(PersonClassConstructorDTO::class.java, arrayOf(kotlin.Int::class.java, kotlin.String::class.java, kotlin.Int::class.java), id, name, age)

Which is incorrect as it should only include properties from the constructor.

For reference kapt will produce this:

@Generated("com.querydsl.codegen.DefaultProjectionSerializer")
public class QPersonClassConstructorDTO extends ConstructorExpression<PersonClassConstructorDTO> {

    private static final long serialVersionUID = 1630917992L;

    public QPersonClassConstructorDTO(com.querydsl.core.types.Expression<Integer> id, com.querydsl.core.types.Expression<String> name) {
        super(PersonClassConstructorDTO.class, new Class<?>[]{int.class, String.class}, id, name);
    }
}

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 14, 2025

Codecov Report

Attention: Patch coverage is 0% with 46 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (1be6776) to head (b92e49b).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...in/com/querydsl/ksp/codegen/QueryModelExtractor.kt 0.00% 30 Missing ⚠️
...tlin/com/querydsl/ksp/codegen/QueryDslProcessor.kt 0.00% 11 Missing ⚠️
...n/kotlin/com/querydsl/ksp/codegen/TypeExtractor.kt 0.00% 4 Missing ⚠️
...main/kotlin/com/querydsl/ksp/codegen/QueryModel.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #1232    +/-   ##
=======================================
  Coverage    0.00%   0.00%            
=======================================
  Files         812     837    +25     
  Lines       31094   31451   +357     
  Branches     3521    3535    +14     
=======================================
- Misses      31094   31451   +357     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@velo velo merged commit 3f07ca2 into master Jun 15, 2025
6 checks passed
@velo velo deleted the fix/query-projection-included-props branch June 15, 2025 12:32
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