mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Invalid field error reported for bigint DBAL type #7251
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @emodric on GitHub (Nov 20, 2023).
Bug Report
Summary
I have an entity with a
bigintprimary key, wich has aninttypehint in the entity class. I realize from the error message thatbigintusesstringinternally, but so far, there was no issues with usinginttypehint, especially, since we do not need values larger than 64bit integers.Current behavior
After upgrading to Doctrine ORM 2.17.1, the above error is shown in logs.
How to reproduce
Expected behavior
No error message is reported.
@greg0ire commented on GitHub (Nov 20, 2023):
Why? As you mentioned yourself,
bigintusesstringinternally. Either you should pick another type, or you should write a custom type that wraps the bigint type and returns anint. Note that you might not be aware of performance issues this can cause, see https://github.com/doctrine/orm/issues/10944@emodric commented on GitHub (Nov 20, 2023):
What I really wanted to say is that it would be nice to allow usage of
bigintwithintPHP typehint, allowing up to 64bit size integer values, without having the warning in the logs.@dmamchyts commented on GitHub (Nov 21, 2023):
The same issue after upgrade from
to
Entity:
error:
@greg0ire commented on GitHub (Nov 21, 2023):
@emodric @dmamchyts it's unclear to me whether you have read and understood https://github.com/doctrine/orm/issues/10944
@emodric commented on GitHub (Nov 21, 2023):
Yes, and so far I haven't had issues with performance.
@greg0ire commented on GitHub (Nov 21, 2023):
Ok, so… if you were starting from scratch, you would not be using
bigintthen, since you don't plan on using values larger than 64 bit integers, right? This must have to do with a wrong, maybe legacy choice that is hard to change now, correct?@emodric commented on GitHub (Nov 22, 2023):
Not really. Isn't
bigintin MySQL used for 64bit integers?https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
@greg0ire commented on GitHub (Nov 22, 2023):
I wrongly thought it would allow integers larger than 64 bits because you stated:
Now I fail to understand the logic in your first message. Did you mean to write "since we do not need values larger than
PHP_INT_MAX"? On my system,PHP_INT_MAXis smaller than2**64@emodric commented on GitHub (Nov 22, 2023):
Well, yes, that's true, I meant
PHP_INT_MAX, which is on my 64bit system equal to2**63 -1, but I said 64bit colloquially, without taking into account signness of the integer value.So, just to be clear, yes, we're using
bigintto allow values up to2**63 - 1, which corresponds to PHP's max integer value on 64bit systems.@dmamchyts commented on GitHub (Nov 22, 2023):
If I understand correctly https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#bigint - in 4.0.0 current issue will be fixed?
Values retrieved from the database are always converted to PHP's integer type if they are within PHP's integer range or string if they aren't. Otherwise, returns null if no data is present.
@greg0ire commented on GitHub (Nov 22, 2023):
Indeed, I forgot about that. The related PR is https://github.com/doctrine/dbal/pull/6177
Not sure what to do now… I don't think there is an upgrade path for this particular breaking change. I think the right course of action for you is to use
stringas a type hint for now, and to add a method that casts it to int. And then, to never access the property directly, always go through the method.Then before migrating to 4.0.0, you change the type to
string|int, ignore the warning, and change tointafter the migration.@dmamchyts commented on GitHub (Nov 22, 2023):
Looks like I can ignore minor/patch releases (if no any performance issues).
Wait for the release of 4.0.0 and only then update libraries
No any changes in code-base.
Do you have any ETA about the release 4.0.0?
@greg0ire commented on GitHub (Nov 22, 2023):
I'd say months if not weeks.
@derrabus commented on GitHub (Nov 22, 2023):
Soon'ish, but it will require you to upgrade to ORM 3 as well.
I have the same issue on one of my projects as well and my fear is that this error incentivizes people to change all their
BIGINTproperties tostringjust to run into the same issue once they upgrade to DBAL 4 one fine day. With a smooth upgrade path in mind, typingBIGINTproperties asintshould be correct and we should try to make it work in ORM 2 already.Also, a lot of projects have the schema validation in their CI (which is good!) and now this new check (which is absolutely reasonable!) blocks the ORM upgrade unless the schema validation is either disabled completely or all errors have been fixed.
In the project where I have this problem, we have twenty-something properties that have the infamous
DECIMAL+floattype mismatch that motivated this new check. Each of them needs an individual solution, so it might take us a while. It would be good, if we could baseline or silence this issue somehow for the time being.@bobvandevijver commented on GitHub (Nov 23, 2023):
I have the same issue with
floatphp type combined withdecimalin the database: for us it is actually a great reminder that we need to update this anyways to something else, but it would indeed be nice to have some method to silence the issue for the time being.@greg0ire commented on GitHub (Nov 23, 2023):
Might be cool to have some kind of baseline concept but for that we would first need to come up with identifiers for each and every issue. Or at least for this one, as a start. Then I guess that system could be developed so that it's possible to baseline issues per entity/property/whatever. Might even be call to use PHP attributes to that end.
Not saying I will build it, but still, might be cool.
@vitxd commented on GitHub (Dec 13, 2023):
Hello, since I've updated doctrine dbal I have this issue as well as others that seems related when using enums as type, for example:
do you think is related?
@greg0ire commented on GitHub (Dec 13, 2023):
I'd need to see
EventTypeto answer that. Also, we might want to improve the code introduced in #11039, it produces an error that does not mention the backing type, Cc @yceruto@yceruto commented on GitHub (Dec 13, 2023):
@vitxd can you show us the mapping code for that field?
@yceruto commented on GitHub (Dec 13, 2023):
What is the backed type of your
App\Enum\EventType?@vitxd commented on GitHub (Dec 13, 2023):
Yes sorry @yceruto, I just realised is an interface. implementations are
the mapping is:
CertificateEvent looks like:
@greg0ire commented on GitHub (Dec 13, 2023):
Then I think it's unrelated, and you should file a separate issue. This is probably specific to either interfaces or enums. I'll mark our conversation as off-topic so that people concerned by the original issue don't bother reading them.
@vitxd commented on GitHub (Dec 15, 2023):
Is this issue being fixed by the way? I have this problem too as well as the other you've already fixed (thanks!)
@mindaugasvcs commented on GitHub (Jan 10, 2024):
Why Doctrine devs did not check PHP_INT_SIZE in Doctrine\DBAL\Types\BigIntType and cast to string for value 4 and cast to int for value 8? :/
@greg0ire commented on GitHub (Jan 11, 2024):
@vitxd there is https://github.com/doctrine/orm/pull/11130 that might be of help
@mindaugasvcs I don't think I 100% understand your question, but having an application behave differently based on
PHP_INT_SIZEsounds like a terrible idea.@mindaugasvcs commented on GitHub (Jan 11, 2024):
Of course always casting to a 'string' is much nicer when in fact it should be int as 32-bit systems are dead by now.
@greg0ire commented on GitHub (Jan 11, 2024):
Ah sorry, I did misunderstand. What you're suggesting is actually more or less what's going to happen with DBAL 4: https://github.com/doctrine/dbal/pull/6177
@greg0ire commented on GitHub (Jan 11, 2024):
Anyway, closing as: