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

For backward compatibility, relax the requirements that transaction meta data (user or description) be text #44

Merged
merged 3 commits into from Mar 11, 2017

Conversation

jimfulton
Copy link
Member

No description provided.

@@ -22,6 +23,7 @@
from transaction.weakset import WeakSet
from transaction.interfaces import TransactionFailedError
from transaction import interfaces
from transaction._compat import binary_type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace binary_type with bytes everywhere. On Python2:

>>> bytes is str
True

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I was just being consistent with the rest of the package.

I'll change the rest of the package to use bytes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, except it's not used by anything else, so it wasn't used before this pr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks.

Copy link
Member

@icemac icemac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM besides two little questions.

if isinstance(s, bytes):
return s.decode('utf-8', 'replace')
else:
return text_type(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So everything besides text and str is ignored – was this intended?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, nothing is ignored here. (None is ignored at the call sites.)

Anything but text generates a warning. Bytes get special treatment by decoding them. Everything else gets "stred" by converting them to text. The later because on the transaction mailing list, somone asserted that Plone sometimes passes ints. .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, RelStorage 1.6 simply ran str(txn.user) and str(txn.description), so it could take anything for those values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Python 3:

>>> str(b'test')
"b'test'"

which seems suboptimal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RelStorage didn't check for None before it ran str, so if user and description were ever set to that (which seems likely, especially for user), there would be 'None' in the database.

My point is, it probably doesn't matter that much 😄

if isinstance(s, text_type):
return s

warnings.warn("Expected text", DeprecationWarning, stacklevel=3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice here to see the actual value which caused the warning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this will cause memory leaks in "warning-once" mode, because the text is part of the key to remember whether a warning was issued or not. This applies to both the builtin (_warnings) and python (warnings) versions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, good point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I undid this in 2.1.2.

@hannosch
Copy link

+1, looks good.

@jimfulton jimfulton merged commit 1029b68 into master Mar 11, 2017
@jimfulton jimfulton deleted the deprecate-non-text branch March 11, 2017 13:16
@jimfulton
Copy link
Member Author

Releases as 2.1.1.

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

Successfully merging this pull request may close these issues.

None yet

5 participants