-
Notifications
You must be signed in to change notification settings - Fork 22
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
Is the Text instance guaranteed to generate legal text? #9
Comments
If what is written at https://hackage.haskell.org/package/quickcheck-text is correct, should those instances be merged in this package?
|
as far as i can tell converting |
Still puzzling me though:
|
I was not aware of About second point: I don't know. By reading
But I don't know for sure, I have no experience with HSTORE, so don't take that as an advice. |
Actually there are two separate issues being discussed in that thread. The first one is where I was pumping a raw HSTORE string, where this is true. The second is where I'm generating an Therefore, digging deeper to understand if it is possible to generate illegal Text values in the first place. |
@phadej's guess is correct:
I wrote |
I'm back again. What could explain the following error from PG:
|
|
Could this explain lpsmith/postgresql-simple#218 (comment) and lpsmith/postgresql-simple#218 (comment) ? Also, is this a good use-case for a PR around generating Text values without |
Maybe. I have no time to investigate. Have you tried generating About the PR. For now, adding modifier |
Maybe. I have no time to investigate. Have you tried generating About the PR. For now, adding modifier |
Okay - let me confirm that |
Possible SolutionConfirmed that this is a |
One possible solution could be to break this package into submodules -- one for each type -- so that users can selectively import the exact instances they need. |
Won't do that. That would impose huge maintainment cost. Just do a The fact that postgres requires |
The practical side is that this has a huge cost in development. All |
I think you're missing @phadej's point. I think he is suggesting that you use the |
Here's a random relevant StackOverflow question I found, in case anyone finds it useful: https://stackoverflow.com/questions/28813409/are-null-bytes-allowed-in-unicode-strings-in-postgresql-via-python |
You are right - this reduces the dev overhead, but there is overhead nevertheless. Every arbitrary instance that was earlier a one-liner:
will now need to be
Unless one writes a custom generic function to do this automagically, I guess. |
Yes, I can see that can become a pain. The alternative is to patch The bug lies in Postgres, of course. |
You could have arbitraryNotNullText :: Gen Text
arbitraryNotNullText = ... then instance Arbitrary MyRecord where
arbitrary = MyRecord
<$> arbitrary
<*> arbitraryNotNullText
<*> arbitrary
<*> arbitraryNotNullText
-- and so on You don't have to use |
This increases friction / boilerplate unnecessarily. Unless NonNullText is a core type in your app, you can't do this without introducing friction. For example, now I can't use a generics or TH library to manage all the Arbitrary instance boilerplate. I concede that it is possible, but if everyone is forced to do this, then either it is not useful, or we need to fix the bug that this uncovers, or we need to change the String/Text types being used by foundational libraries. |
I think this is a limitation of Generics/TH libraries that can be overcome with an option to insert your own implementation of |
@saurabhnanda How's this, to patch generators for specific types (or fields), with generic-random-1.1.0.0: -- write once
genPG :: GenList '[Text]
genPG = (genPGCompatibleText :: Gen Text) :@ Nil
instance Arbitrary MyRecord where
arbitrary = genericArbitraryUG genPG |
Is this line guaranteed to generate legal text values? My naive understanding of legal text values is stuff that has something to do with legality in a UTF sense.
Is the test failure at lpsmith/postgresql-simple#218 (comment) somehow related to the underlying text values being generated?
The text was updated successfully, but these errors were encountered: