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

[Bug]: Formula set as ScalarReference not loaded as LoadedScalarReference at runtime #5557

Closed
5 tasks done
kpervin opened this issue May 10, 2024 · 6 comments
Closed
5 tasks done

Comments

@kpervin
Copy link
Contributor

kpervin commented May 10, 2024

Describe the bug

When using a formula with a lazy scalar reference, it appears as type ScalarReference or LoadedScalarReference when using the .load(), .get(), or .$ methods. However, at runtime, all properties are lost and the field is loaded as the formula value. Additionally, in MySQL, if set to a Boolean type, it does not serialize and ends up as a TinyInt.

Reproduction

https://github.com/kpervin/mikro-orm-reproduction/tree/lazy-scalar-reference-issue

Please note that this is using the SQLite default. Testing with MySQL should also be done to see the serialization issue.

What driver are you using?

MySQL

MikroORM version

next

Node.js version

20.9.0

Operating system

5.15.146.1-microsoft-standard-WSL2

Validations

@kpervin kpervin changed the title Formula set as ScalarReference not loaded as LoadedScalarReference at runtime [Bug]: Formula set as ScalarReference not loaded as LoadedScalarReference at runtime May 10, 2024
@kpervin
Copy link
Contributor Author

kpervin commented May 13, 2024

Closing due to realizing that the ref option was required. Was under the impression that it would have been picked up by TsMorphMetadataProvider.

@kpervin kpervin closed this as completed May 13, 2024
@B4nan
Copy link
Member

B4nan commented May 13, 2024

Let's keep this open, I want to review it first (probably this evening). ts-morph should pick this up, and it might be failing because you use it with the Opt type intersection. Note that your repro does not use ts-morph.

@B4nan B4nan reopened this May 13, 2024
@kpervin
Copy link
Contributor Author

kpervin commented May 13, 2024

Yes, I saw that before I closed the issue. Required a bit of refactoring for it to work. It has now been added.

@B4nan
Copy link
Member

B4nan commented May 13, 2024

Yeah, this is surely something to fix, it's about the Opt type intersection. Note that in your repro you test whether the value is true - it never will be the value itself with the Ref wrapper, it is always the Reference class (in this case ScalarReference), which wraps the value.

@B4nan
Copy link
Member

B4nan commented May 13, 2024

So the problem here is that the TS compiler API returns the type for hasBarPost as any for some reason. If you use hasBarPost!: Opt<Ref<boolean>> it does work fine though.

edit: Damn, I again forget that the compiler API likes to give any in the ORM test suite while it works outside of it. So the type name actually resolves to (import("/Users/adamek/htdocs/mikro-orm/reproduction/node_modules/@mikro-orm/sqlite/index").ScalarReference<false> | import("/Users/adamek/htdocs/mikro-orm/reproduction/node_modules/@mikro-orm/sqlite/index").ScalarReference<true>) & { [__optional]?: 1 | undefined; }, and we fail to process that properly. Uh and why the hell it expands boolean to true | false.

@B4nan B4nan closed this as completed in 534f088 May 14, 2024
@kpervin
Copy link
Contributor Author

kpervin commented May 14, 2024

Wow, what a simple fix for such a weird issue haha

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

No branches or pull requests

2 participants