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
TypeError : section names must be strings #921
Conversation
|
I don't understand this change; why is the section no longer added to config? |
|
The reason that cause the change is first the error mentioned in commit
message and second I tried to test it with different fructose activities ,
I first tried with write then with chat and with same friend. I found
duplicate section error with chat , that means if a friend is already added
in a section , no means to add it again as ConfigParser works as a
dictionary , it can't contain duplicate keys. Second this I don't know why
it's not working see if you could help with that is whenever a user exists
with activity along with his friend , its section should be deleted. Seems
like there is no option to delete or it's not working.
…On Tue 2 Jun, 2020, 7:04 AM James Cameron, ***@***.***> wrote:
I don't understand this change; why is the section no longer added to
config?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#921 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKZH63JVIKKQGTFQ7UQPOXDRURJKNANCNFSM4NQAXQRQ>
.
|
|
If section is already present , no need to set it again according to me.
…On Tue 2 Jun, 2020, 10:28 AM Srevin Saju, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/jarabe/model/friends.py
<#921 (comment)>:
> @@ -156,9 +156,10 @@ def save(self):
cp = ConfigParser()
for friend in self:
- section = friend.get_key()
- cp.add_section(section)
- cp.set(section, 'nick', friend.get_nick())
+ section = str(friend.get_key())
+ if section not in cp.sections():
+ cp.add_section(section)
+ cp.set(section, 'nick', friend.get_nick())
Should L#162 be outside the if conditional code block?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#921 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKZH63LXZG5HLCKMF4VDMKLRUSBJFANCNFSM4NQAXQRQ>
.
|
|
@Saumya-Mishra9129 I guess the section is added in L161; The section should be updated with the new information right? |
I had asked why the section is no longer added. My question was wrong. You should have pointed that out. Only now do I see that the GitHub inline comment stream hid the remainder of the patch. The section is not no longer added. But I still don't understand, and the commit message hasn't changed; I don't see the traceback, so I can't validate the commit does what it says. The nick should be set again, as it may have changed without the key changing. Also, section names must be strings has nothing to do with duplicate sections, so I think you are perhaps conflating the two problems; please use separate commits for separate problems. |
Yeah that is what needed. |
|
Thanks for the update. This is a critical repository, so my standards of review are much higher. Still there's not enough detail in the commit message. I want to see the summary line say what you fix, but not expressed as an error message unless that error message is the only evidence of a harmless problem. I want to see in the commit message the complete traceback message, from the first line which says Traceback to the error. Please read making commits and follow the advice in each point where possible, and ask if you need me to clarify. I'd also like to know why the key property is not a string already. How is it that it has become a bytes? What set the property? Are there any other uses of the property in other source code in the toolkit and activities that presume it is a string? I've done a quick search and I've found some uses of the property that seem to suggest it should be a string. Because of this, I'm not sure if what you propose is the right solution. |
|
The current solution might be a workaround to solve the problem The source of the This a possible test case, |
|
I logged about get_key return value it returns |
|
Why is it not |
I finally find out the place where key has set to byte aa18879#diff-644e16988bb8fd551b1f0c2f32a6b2a3R164. @srevinsaju as James is not available .. can you see if I am correct or not.? |
|
@Saumya-Mishra9129 it looks like the source of bytes is correct as you have pointed out. EDIT: I have checked a recursive |
I checked it didn't work , got stuck in another error. But I am sure the key value is in bytes here. This is possibly the a regression, but I am still not able to find the right cause. :( |
|
The use of bytes might be also because of the use of sockets. Most sockets require only data as bytes. This might be another reason. I do not have extensive knowledge on this. Maybe @shaansubbaiah might know. He had recently finished a great PR #911, amazing work there. May be he can help |
|
Just to remind you, that sugarlabs/sugar-toolkit-gtk3#433 is where the object is quoted bytes, not bytes. I suggest black-box testing D-Bus and checking if it is data clean. |
|
Sorry for the late reply, what is the error seen after removing the |
Thanks @shaansubbaiah , The error was straight forward in sugar/src/jarabe/model/buddy.py Line 165 in aa18879
|
|
I've reviewed the discussion so far.
|
|
@quozl @srevinsaju Please review bfae395 and 8a065b3. 8a065b3 solves the error mentioned in mailing list by @shaansubbaiah
Can you test and confirm that it doesn't happen with above changes.? |
|
Reviewed 8a065b3, haven't tested yet but I don't think it'll fix the issue. Have you tested? Reason why I don't think it'll fix the issue is because in the commit, the only functional change is the change from |
I have tested it. It fixes the problem for me. The key was a quoted bytes because we were taking it as str. It should be treated as object as it is treated in add-friend. Can you test it once? |
|
Reviewed 8a065b3. This changes the API. I don't know of anything using the API apart from Sugar, but I'm sensitive to changes to API because of the later damage that can happen. Specific change is friend-removed signal is now given an object (something with a get_key method which is called) instead of a str (with the key already provided). I don't see why this change is made. The commit message doesn't explain. While it may well remove the KeyError, it doesn't seem likely to be correct as a solution. Why isn't str changed to bytes instead? |
I agree, changes to APIs can be critical, and should have done after proper testing. The major reason why I go with this change is that key is seen as quoted bytes , which means a str object. in that error message. It could be because we had used str . The add-friend also uses an object there , so why not we use same object in both instead of str , and however if we allow this change , the next person who will use API somewhere will proceed accordingly in future. This error makes (F2) Group View a lot messy, because it keeps on adding friends objects there without any removal. |
|
I don't feel my questions have been answered. I'll try again. 8a065b3 is three changes at once;
Which of these changes is responsible for fixing the problem, and why? None of these changes affect how data is converted, so the problem of quoted bytes should be unchanged. Is it really that the get_key method is returning different type depending on when it is called? |
All of them are necessary, as changing The output is - It clears that even if we add bytes object in list, when delete signal is called , it automatically converts bytes to str . Hence key error is raised because of quoted bytes. |
|
Then why not pass a |
|
Thanks. Reviewed. The root cause of both problems is our failure to Port to Python 3 with respect to the D-Bus interface being used to obtain the connection interface buddy info from Telepathy. Instead of these two patches, I recommend 95b1c32 ("Coerce BaseBuddyModel.props.key to str"). This patch reverts and reimplements a tiny part of aa18879 ("Port to Python 3"). Please review. |
Nobody answered, so I've tested. PyGObject cannot have |
In Group View when a friend is made a traceback occurs.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/jarabe/view/buddymenu.py", line 205, in _make_friend_cb
friends.get_model().makefriend(self._buddy)
File "/usr/lib/python3/dist-packages/jarabe/model/friends.py", line 130, in make_friend
self.save()
File "/usr/lib/python3/dist-packages,jarabe/model/friends.py", line 160, in save
cp.add_section(section)
File "/usr/lib/python3.8/configparser.py", line 1207, in add_section
self._validate_value_types(section=section)
File "/usr/lib/python3.8/configparser.py", line 1180, in _validate_value_types
raise TypeError("section names must be strings")
TypeError: section names must be strings
In Group View when a friend is removed a traceback occurs.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/jarabe/desktop/groupbox.py", line 67, in _friend_removed_cb
icon = self._friend[key]
KeyError: "b'AAAA0...'"
Regression introduced aa18879; a
BaseBuddyModel.props.key is coerced to bytes before being sent to
Telepathy.
Telepathy API for connection interface buddy info key uses a
dbus.ByteArray.
A dbus.ByteArray is now a subclass of bytes, where in Python 2 it is a
subclass of str.
https://dbus.freedesktop.org/doc/dbus-python/PY3PORT.html
When the buddy key is set from bytes, convert to str in utf-8 encoding.
When the buddy key is sent to Telepathy, convert to bytes.
Signed-off-by: James Cameron <quozl@laptop.org>
Thanks @quozl , I have reviewed and tested. Looks perfect to me and with no errors in the log. The root cause was very simple and even the fix also was. I am now happy to see it this way . |
|
@quozl I think we can merge this. |

Steps to produce - open a fructose activity such as write on VM , click on neighbourhood icon , join on other VM , then stop activities on both VMs.