-
Notifications
You must be signed in to change notification settings - Fork 94
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
save the repr of template variables in database #4864
save the repr of template variables in database #4864
Conversation
I think we should be either storing the "raw" strings or the Python Storing the type as a separate field won't work because types can be nested e.g. |
20772a0
to
47ea104
Compare
47ea104
to
ce77fa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to test manually but looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, tested as working 🎉
ff756a9
to
20772a0
Compare
I've badly messed up branches - fixing before undrafting. |
20772a0
to
a90dd45
Compare
I think a changelog entry wouldn't go amiss. Also a short description of the fix in the PR body, for the benefit of us from the future? |
FYI: For piece of mind I had a quick crack at checking that
from ast import literal_eval
from itertools import combinations_with_replacement
def range2(*args):
for number in range(*args):
print(f'# {number}')
yield number
def generate(length):
"""Generate random strings with "length" characters."""
for chars in combinations_with_replacement(
'\'"-_+=()<>[]{},./a1',
length
):
yield ''.join(chars)
def parse(string):
"""Return True if the string is a valid Python literal."""
try:
literal_eval(string)
except Exception:
return False
return True
def test(string):
"""Ensure repr/literal_eval can serialise/deserialise this value."""
value1 = literal_eval(string)
try:
value2 = literal_eval(repr(value1))
except Exception:
return False
return value1 == value2
invalid_reprs = (
string
for length in range2(0, 20)
for string in generate(length)
if parse(string)
if not test(string)
)
for item in invalid_reprs:
print(item) Some of the things
Worth being aware that these are valid template variables! |
Can I get a final check @oliver-sanders and @MetRonnie |
Nice, but isn't that exactly the purpose of repr (so it had better work!)? |
In theory, yes, in practice however, it is implemented on a type-by-type basis (e.g. |
These changes close #4862
Requirements check-list
CONTRIBUTING.md
and added my name as a Code Contributor.setup.cfg
andconda-environment.yml
.