Skip to content

Commit c33aef5

Browse files
committed
Don't set delta to updated if already set to added
If an attribute is added multiple times, it's delta value should still be ADDED - not UPDATED.
1 parent 670148f commit c33aef5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ public void setAttribute(String attributeName, Object attributeValue) {
735735
if (attributeValue == null) {
736736
this.delta.put(attributeName, DeltaValue.REMOVED);
737737
}
738-
else if (this.delegate.getAttribute(attributeName) != null) {
738+
else if (this.delta.get(attributeName) != DeltaValue.ADDED && this.delegate.getAttribute(attributeName) != null) {
739739
this.delta.put(attributeName, DeltaValue.UPDATED);
740740
}
741741
else {

spring-session-jdbc/src/test/java/org/springframework/session/jdbc/JdbcOperationsSessionRepositoryTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,25 @@ public void saveUpdatedModifySingleAttribute() {
373373
verifyZeroInteractions(this.jdbcOperations);
374374
}
375375

376+
@Test
377+
public void saveUpdatedModifySingleAttributeTwice() {
378+
JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey",
379+
new MapSession());
380+
session.setAttribute("testName", "testValue");
381+
session.clearChangeFlags();
382+
session.setAttribute("testName", "testValue");
383+
session.setAttribute("testName", "testValue");
384+
385+
this.repository.save(session);
386+
387+
assertThat(session.isNew()).isFalse();
388+
assertPropagationRequiresNew();
389+
verify(this.jdbcOperations, times(1)).update(
390+
startsWith("UPDATE SPRING_SESSION_ATTRIBUTES SET"),
391+
isA(PreparedStatementSetter.class));
392+
verifyZeroInteractions(this.jdbcOperations);
393+
}
394+
376395
@Test
377396
public void saveUpdatedModifyMultipleAttributes() {
378397
JdbcOperationsSessionRepository.JdbcSession session = this.repository.new JdbcSession("primaryKey",

0 commit comments

Comments
 (0)