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

NamedParameterUtils has broken square brackets handling #27925

Closed
artembilan opened this issue Jan 12, 2022 · 3 comments
Closed

NamedParameterUtils has broken square brackets handling #27925

artembilan opened this issue Jan 12, 2022 · 3 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: regression A bug that is also a regression
Milestone

Comments

@artembilan
Copy link
Member

artembilan commented Jan 12, 2022

This is a simple unit test which passes with the 5.3.x but fails with the current 6.0 milestones:

	@Test
	void namedParamMapReference() {
		String insert = "insert into foos (id) values (:headers[id])";
		class Foo {

			final Map<String, Object> headers = new HashMap<>();

			public Foo() {
				this.headers.put("id", UUID.randomUUID());
			}

			public Map<String, Object> getHeaders() {
				return this.headers;
			}

		}

		Foo foo = new Foo();

		Object[] params =
				NamedParameterUtils.buildValueArray(NamedParameterUtils.parseSqlStatement(insert),
						new BeanPropertySqlParameterSource(foo), null);

		assertThat(params[0]).isEqualTo(foo.getHeaders().get("id"));
	}

The point is that we may have a reference for the value from nested Map property.

The typical use case is messaging, for example with Spring Integration, where a Message<?> in the request is used as a source for parameter values.

We even advertise this in the docs: https://docs.spring.io/spring-integration/docs/current/reference/html/jdbc.html#jdbc-outbound-channel-adapter.

I suspect that the cause for breaking change is this fix: 64b6bee. Or the previous one: 86eda27.

Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 12, 2022
@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) type: regression A bug that is also a regression labels Jan 12, 2022
@sbrannen sbrannen added this to the Triage Queue milestone Jan 12, 2022
@quaff
Copy link
Contributor

quaff commented Jan 17, 2022

parameterName is changed from headers[id] to headers after commit 64b6bee

@jhoeller jhoeller removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 18, 2022
@jhoeller jhoeller modified the milestones: Triage Queue, 6.0.0-M3 Jan 18, 2022
@jhoeller jhoeller self-assigned this Mar 16, 2022
@jhoeller jhoeller modified the milestones: 6.0.0-M3, 6.0.0-M4 Mar 16, 2022
@jhoeller jhoeller modified the milestones: 6.0.0-M4, 6.0.0-M5 May 4, 2022
@jhoeller jhoeller modified the milestones: 6.0.0-M5, 6.0.0-M6 Jul 8, 2022
@jhoeller jhoeller modified the milestones: 6.0.0-M6, 6.0.0-RC1 Sep 12, 2022
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Oct 11, 2022

Maybe consider #17773 as well for potential improvement to the parsing algorithm.

@jhoeller jhoeller modified the milestones: 6.0.0-RC1, 6.0.0-RC2 Oct 11, 2022
@jhoeller
Copy link
Contributor

jhoeller commented Oct 18, 2022

With some custom treatment, we can restore the original intent of #27716 as well as preserve square brackets for index/key expressions. Finally making it into RC2...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

6 participants