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

Confusing error message when reading a non-existing Field from a Record containing accidentally nested row types #15085

Closed
lukaseder opened this issue May 17, 2023 · 4 comments

Comments

@lukaseder
Copy link
Member

Since jOOQ 3.17, users may be accidentally nesting records in their queries:

An example:

ctx.select(CONFIGURATION)
   .from(CONFIGURATION)
   .where(CONFIGURATION.DEVICE_ID.eq(id))
   .fetch();

When trying to read a CONFIGURATION column from the resulting nested record, this error message appears:

Exception in thread "" java.lang.IllegalArgumentException: Field ("public"."configuration"."minimum_temperature_threshold") is not contained in Row (row (
  "public"."configuration"."configuration_id",
  "public"."configuration"."minimum_temperature_threshold",
  "public"."configuration"."maximum_temperature_threshold",
  "public"."configuration"."ideal_temperature",
  "public"."configuration"."minimum_ph_threshold",
  "public"."configuration"."maximum_ph_threshold",
  "public"."configuration"."ideal_ph",
  "public"."configuration"."light_on_time",
  "public"."configuration"."light_off_time",
  "public"."configuration"."update_time",
  "public"."configuration"."device_id"
))

The fact that Row (row ( means the row is nested is too subtle to debug this. It appears that the requested column is right there!

Probably, the error message can be improved to help users here.

@lukaseder
Copy link
Member Author

I'll try this error message:

Field "ID1" is not contained at the top level of row type containing nested row types (row ("TABLE1"."ID1", "TABLE1"."NAME1", "TABLE1"."DATE1"))

The problem is really specific to the fact that the row type is Record1<NestedRecordType> in this particular case. If multiple nested row types are available (e.g. Record3<Integer, String, NestedRecordType>), then I think the API usage and error messages are less confusing.

As a side note, it might be possible to allow such access of nested row attributes via top level column references, pretending the record is flat. I'm not sure yet if this is a good idea, but here's a feature request for this:

@lukaseder
Copy link
Member Author

Without actually implementing #16721, some of its logic can already be implemented to help with the error message, though. I.e. we can look up the ID1 column in all nested rows and check if we would have found it if #16721 was implemented, and then hint at the mistake.

@lukaseder
Copy link
Member Author

This message improvement should also apply to index based field access

@lukaseder lukaseder added this to To do in 3.20 Other improvements via automation May 28, 2024
@lukaseder lukaseder changed the title Confusing error message when reading a non-existing Field from a Record Confusing error message when reading a non-existing Field from a Record containing accidentally nested row types May 28, 2024
3.20 Other improvements automation moved this from To do to Done May 28, 2024
lukaseder added a commit that referenced this issue May 28, 2024
Field from a Record containing accidentally nested row types
lukaseder added a commit that referenced this issue May 28, 2024
Field from a Record containing accidentally nested row types
lukaseder added a commit that referenced this issue May 28, 2024
Field from a Record containing accidentally nested row types
lukaseder added a commit that referenced this issue May 28, 2024
Field from a Record containing accidentally nested row types
lukaseder added a commit that referenced this issue May 28, 2024
Field from a Record containing accidentally nested row types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant