Skip to content
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

fix: EXPOSED-694 Entities insertion could fail if batches have different column sets #2365

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

obabichevjb
Copy link
Collaborator

Description

If there are multiple entities that have different set of columns inside writeValues the flush of these entities could fail. The reason is the batch insert that will have different column sets for different entities.

It happens if the id field of that entity has client side default value. Otherwise entity's writeValues will be extended with default values inside EntityClass::new(). Actually, the check for that extending looks suspicious and has the following form:

if (entityId._value == null) {
    val readValues = prototype._readValues!!
    val writeValues = prototype.writeValues
    table.columns.filter { col ->
        col.defaultValueFun != null && col !in writeValues && readValues.hasValue(col)
    }.forEach { col ->
        writeValues[col as Column<Any?>] = readValues[col]
    }
}

As I can see (according to the tests) that extending is needed to prevent multiple reads of default values from the table object.

Solution: at the current moment I solved the problem on the step of creating batch insert for the new entities. Entities could be partitioned by column sets to prevent inconsistent batch inserts. In the worst case it could lead to insertion entities one-by-one. But in the case of small amount of columns and large amount of entities it would not be a problem.


Type of Change

Please mark the relevant options with an "X":

  • Bug fix

Affected databases:

  • All

Related Issues

EXPOSED-694 Entities insertion could fail if batches have different column sets

@obabichevjb obabichevjb self-assigned this Jan 21, 2025
@obabichevjb obabichevjb requested a review from bog-walk January 21, 2025 14:09
@obabichevjb obabichevjb merged commit 7beb628 into main Jan 31, 2025
5 checks passed
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