Skip to content

Adapt tests that expected a DuplicateKeyException #2113

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

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

marcusdacoregio
Copy link
Contributor

Closes gh-2108

@marcusdacoregio marcusdacoregio added status: duplicate A duplicate of another issue type: enhancement A general enhancement type: breaks-passivity This issue breaks passivity in: jdbc labels Jul 18, 2022
@marcusdacoregio marcusdacoregio added this to the 3.0.0-M3 milestone Jul 18, 2022
@marcusdacoregio marcusdacoregio self-assigned this Jul 18, 2022
@marcusdacoregio
Copy link
Contributor Author

Hi @vpavic.

Would you mind sharing your feedback about this PR? Or maybe you have another solution to share.

Thank you.

@vpavic
Copy link
Contributor

vpavic commented Jul 19, 2022

Hi @marcusdacoregio - I'll try to take a closer look at this over the next day or two. Hopefully that's OK, as I see no due date set on the 3.0.0-M3 milestone.

Copy link
Contributor

@vpavic vpavic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After taking a look at this, my opinion is that due to the JDBC SessionRepository having some quite specific error handling scenarios that have been established over the years (based on user feedback, mostly involving high concurrency use cases), there is a need for a more sophisticated SQL exception translation than the one that's present by default in Spring Framework starting with 6.0.

So basically, what I'm saying is that the JdbcTemplate that's configured in Spring Session's JDBC configuration infrastructure should set up an exception translator that's capable of telling DuplicateKeyException apart from DataIntegrityViolationException.

Note that not ensuring such behavior out of the box effectively means that catch blocks expecting DuplicateKeyException are dead code, unless users configure JdbcIndexedSessionRepository by themselves supplying JdbcTemplate with appropriate exception handling configured.

Also, I don't think this warrants being labeled as breaking change (label type: breaks-passivity) since there's really nothing breaking in the Spring Session change.

Comment on lines +501 to +505
if (logger.isTraceEnabled()) {
logger.trace("Not able to create session attributes", ex);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call to log this - I'd even consider logging it on debug level.

Minor nit: I'd move logging code beneath the comment block so that the intent of the whole catch block is described first (more readable IMO).

Comment on lines +521 to +525
if (logger.isTraceEnabled()) {
logger.trace("Not able to create session attributes", ex);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same things to consider as in the other comment.

@marcusdacoregio
Copy link
Contributor Author

marcusdacoregio commented Jul 20, 2022

Thank you @eleftherias and @vpavic.

With your valuable feedback, I've decided to use the SQLErrorCodeSQLExceptionTranslator class by default in JdbcTemplate, this way we keep the behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: jdbc status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants