-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add "unique" field validation #6850
Conversation
Thanks. |
Should we add the front-end part as well ?, Like we have in the user creation/modification dialog with the login. |
How would you do front end without doing a query to check each input which
is an overhead?
…On 11 Dec 2017 9:11 pm, "Clément Tamisier" ***@***.***> wrote:
Should we add the front-end part as well ?, Like we have in the user
creation/modification dialog with the login.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6850 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABDlF-dw_WB31Ni7Buz7TgBJFygTTr5Rks5s_YxmgaJpZM4Q9zgE>
.
|
For me we already have this use case with the I'm just thinking it has to be same if we want to handle unicity in entities. |
@gmarziou Yes, I tested it by adding unique to one of the entities and manually checking the generated liquibase file, but I wasn't sure if I should commit that change. I will add it. However, I was actually looking for a proper automated test, where the generated liquibase file would actually be compared against an expected liquibase file, instead of visually checking it. Do you have such a test somewhere? @ctamisier Adding the unique constraint will enforce uniqueness on the DB level, but I have no clue how the error would be shown to the user. I was hoping it would just "automagically" work :) Maybe the exception would be handled on the server side by the global exception handler, translated to a zalando problem, which would then be properly handled on the client side? If changes are needed for this to work, I can do it. However, I'm very new to JHipster. Could you please point me to the actual code that needs to be changed? |
@gmarziou I pushed a change to Division.json. Ran However, I'd like to add an automated test for this. I'm thinking to:
Any idea where exactly could I add such a test case? Or maybe my approach is completely wrong, we should check that the constraint works by adding some kind of higher-level test, where we attempt to create another Division with the same name? |
@taurus227 @ctamisier no we don't want to handle this in the UI as it's complicated to generate and that's why I was originally against adding this validation type. IMO this is already good enough if you want to enforce the uniqueness of a field but if you want more like client-side validation and nice messages I guess you have to implement this based on your business need. |
@taurus227 its not nice to mix Travis tests and unit tests, if you want to unit test this I suggest to take a look at the karma tests, you can do comparisons there easily, look at the test-entity.spec |
I'm merging it as its good enough for what we originally agreed to support. @taurus227 can you update the docs in jhipster.tech and may be update jhipster-core to support this in JDL? |
@deepu105 roger that |
@deepu105 My goal is to unit test my own changes in |
Sorry yes Karma is not exactly unit tests, but you can indeed do this in
|
This has problems with our tests : if an entity A has 2 required relationships to the same entity B and B has a unique field. We already had the case with User that has |
@cbornet Sorry, I don't understand what you mean about the relationships between A and B. Could you give a more detailed example? |
I'm sorry I didn't follow this, and I have some issues with this code:
-> for me this is too early to release this. My proposal is simply to remove this in the question, so that people don't "see" it, but keep the rest of the code. As I'd like to do a release today, please forgive me if I force this, we can still put the question back easily. |
@jdubois In the original issue @deepu105 mentioned that "To really validate something is unique before saving it you need to compare it against existing items to determine if unique which is costly and tricky operation." I agree. And even if you do that, you will still have a concurrency risk: somebody might add the same value after you have checked if it exists, but before you try to commit your transaction, so you still need the constraint and you still might only catch the duplicate value at commit time with that constraint. So the constraint violation error should be handled nicely (with a user-friendly error message) even if a check would be implemented at the UI level. I would argue that most use cases would generate duplicate values rarely, so the check at the UI level adds value rarely in exchange for a performance overhead that will always be there, so I would only implement the constraint at the DB level and if somebody has a use case that creates duplicates often, they can add the extra query to that workflow. I know nothing about MongoDB, but it seems it has unique indexes as well: https://docs.mongodb.com/v3.2/tutorial/unique-constraints-on-arbitrary-fields/ |
@taurus227 thanks, let me take my points in order:
|
What does "hint" mean? Some "sign" that would let the user know that we expect him to enter a unique value, similar to a star showing that a field is required? Or just some instant feedback, like when entering a user name on some websites, it displays "Available" or "Already exists"? |
Yes, I meant some sort of visual indicator, but I understand this is too vague and this is going to take time to decide - so let's forget about it. What happens currently when there is an error, do you have some kind of server-side error that pops up? |
I created #6860 |
This is why I was originally against adding a unique validation, and
somewhere along the line somebody convinced me :P I forgot who and how, but
given the issues, I would vote to revert this for now and if there is a
nice solution addressing all concerns we can consider it back
Thanks & Regards,
Deepu
…On Wed, Dec 13, 2017 at 2:23 PM, Christophe Bornet ***@***.*** > wrote:
I don't understand what you mean about the relationships between A and B.
Could you give a more detailed example?
I created #6860
<#6860>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6850 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABDlF2IA_jtC44uEcPyY9AkTPGB5g2sLks5s_8-1gaJpZM4Q9zgE>
.
|
Don't kill it now... That would mean this will never be done. |
I have plenty of emails, slugs, etc. in my database, and wouldn't mind a "unique" feature like this one. A database error message is good for me for now, it could be improved in feature released. My 2 cents |
I'm going to do a release "anytime soon", and as this isn't 100% complete I'm going to comment out the question in the sub-generator. I will link my commit here, and it will then be easy to roll-back it. |
having this http response:
|
Thanks @ctamisier -> so if we just rely on database constraints (which is not optimal and only works with SQL databases, but as we said it's much easier), then we should at least have a nice error message for this. |
@jdubois I mentioned earlier that MongoDB also has unique constraints. Yes, totally agree, I think we should return a zalando problem to have a nice error message displayed on the UI side? |
@taurus227 well if you can do MongoDB that great, but on a first release there's no need to support everything |
This is a pull request for single-field unique constraints, as discussed in this issue: Adding commands for unique constraints
It includes fixes for the findings detailed in the previous pull request.