Comments (8)
I think it's worth looking at how the built-in types handle this. Something like the DateTime is a good example, because it also needs to get a value that is either a DateTime or can be converted to one.
Looking at the code there I see the same logic: if $value cannot be converted to what we need, throw an exception.
(I should probably note that DBAL does not throw an exception if you use the built-int Guid field. It doesn't check anything there and treats the field as a regular text field. )
Another reason why I like having this exception is that you know there will never be a row that matches an invalid uuid, so you can avoid bothering the database in this case.
Lastly, I feel that there is a difference between "there are no rows that match your query" and "your query is invalid", but that depends on the application.
from uuid-doctrine.
@phoenixgao, looks like the ConversionException is the correct approach here. Either catch that exception or use Uuid::isValid()
before making your query to determine whether the UUID is valid.
Thanks, everyone, for your help!
from uuid-doctrine.
My guess is that you're hitting that ConversionException either here (if using type uuid_binary
) or here (if using type uuid
).
In either case, when preparing the query for the database, the type attempts to convert the value to a UUID for the database, and it fails because the value is invalid.
The ConversionException is from Doctrine\DBAL\Types
, and it makes sense when attempting to store a value to the database, but it doesn't necessarily make sense when doing queries. Since I'm not a power Doctrine user, I'll ask around to see how others handle similar cases.
Thanks!
from uuid-doctrine.
@phoenixgao @ramsey it's exactly that... before even running the query, DBAL tries to convert the data into dabase type.
You would never have a null
return in that case.
from uuid-doctrine.
@lcobucci Is there a better way to handle this for queries? I assume the OP's desire is to actually make the query and get back 0
results.
from uuid-doctrine.
Is there a better way to handle this for queries?
That's a good question... I see that conversion error as a precondition for your query and I'd say that we should filter/sanitize the value before reaching that area. But as @willemwollebrants said "that depends on the application".
from uuid-doctrine.
I think the conversion exception is correct behaviour here.
Either catch the exception and handle or pre-screen your input for validity.
from uuid-doctrine.
Yes at first I was considering the uuid field as just a regular string field, so I expected 0 results from database, but as @willemwollebrants pointed out, even in the database it's a string field, but in php it should be considered as a special uuid field and should let the query hit db only if it is a valid uuid value, since the application should already know that field is a uuid field, then all make sense now.
So for my case I think what I should do is create a validation constraint which calls Uuid::isValid() use the symfony build-in uuid constraints to validate the uuid in the request parameters and return a 400 if it's not valid.
Thanks everyone!
from uuid-doctrine.
Related Issues (20)
- doctrine.yaml configuration issue HOT 1
- Type missmatch in generator with static PHP Mapping (LazyUuidFromString to property Uuid) HOT 3
- There is a bug in MariaDB 10.5.9, extremly slowing queris with UUID in binary form HOT 2
- uuid_binary_ordered_time not working with IN expression HOT 8
- Doctrine 3 compatibility HOT 1
- Imcompatible with the latest Doctrine 2.10 HOT 2
- doctrine.dbal.default_connection is set to 'default' and cannot be changed anymore HOT 2
- Deprecation notice after updating from Symfony 5.3 to 5.4 HOT 2
- Tag new release HOT 1
- Supportfor typed property. HOT 4
- Support other types of `EntityManagerInterface` too HOT 2
- Fetching metadata from an entity using the custom strategy is throwing an error. HOT 2
- Node of UUID is 0 HOT 1
- Additional usage of UUID v6/v7 for UuidBinaryOrderedTimeType HOT 7
- Converting my entities ids to uuids
- Tag a new release HOT 1
- Fetching association throws "Unknown parameter type, 116 given" exception HOT 6
- PostgreSQL UUID type returns a binary stream; DB to PHP conversion is always null HOT 5
- Object of class Ramsey\Uuid\Lazy\LazyUuidFromString could not be converted to int HOT 1
- Doctrine/dbal v4 is out!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uuid-doctrine.