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

banMacros default value "" str incompatible with usages assuming dict #8

Open
Nommabelle opened this issue Dec 15, 2022 · 3 comments
Open

Comments

@Nommabelle
Copy link

Nommabelle commented Dec 15, 2022

For starters, many thanks for offering this library! It's great :) (and used here by me)

Exception when banMacros isn't defined in toolbox config. This can be resolved user-end by defining a ban macro, but could be improved here

banMacros init'd to "" if doesn't exist:

ToolboxSettings.load()
		for item in ["domainTags", "removalReasons", "modMacros","banMacros"]:
			if item not in page.keys(): page[item] = ""

banMacros passed to from_dist with "" if didn't exist:

SettingsRoot.from_dict()
		_banMacros = BanMacros.from_dict(obj.get("banMacros"))

"".get() no bueno:

BanMacros.from_dict()
	def from_dict(obj: Any) -> 'BanMacros':
		_banNote = str(obj.get("banNote"))
		_banMessage = str(obj.get("banMessage"))
		return BanMacros(_banNote, _banMessage)

https://github.com/adhesivecheese/pmtw/blob/main/pmtw/settings.py#L27

Logs:

2022-12-15T16:50:02.903 app[7366d868] ord [info] File "/usr/local/lib/python3.10/site-packages/pmtw/settings.py", line 239, in from_dict

2022-12-15T16:50:02.903 app[7366d868] ord [info] _banMacros = BanMacros.from_dict(obj.get("banMacros"))

2022-12-15T16:50:02.903 app[7366d868] ord [info] File "/usr/local/lib/python3.10/site-packages/pmtw/settings.py", line 27, in from_dict

2022-12-15T16:50:02.903 app[7366d868] ord [info] _banNote = str(obj.get("banNote"))
@HaydenElza
Copy link

HaydenElza commented Dec 27, 2022

Same thing with removal reasons and mod macros. I was able to fix this on my end by creating a dummy removal reason header text, then removing it; creating a dummy mod macro, then removing it; and finally creating a dummy ban macro, then removing it.

When looking at the diff we can see that those parts were initialized by the adding then removing causing them to be dictionaries as expected rather than strings:

{
    "ver": 1,
    "domainTags": "",
-    "removalReasons": "",
+    "removalReasons": {
+        "pmsubject": "",
+        "logreason": "",
+        "header": "",
+        "footer": "",
+        "removalOption": "suggest",
+        "typeReply": "reply",
+        "typeStickied": false,
+        "typeCommentAsSubreddit": false,
+        "typeLockComment": false,
+        "typeAsSub": false,
+        "autoArchive": false,
+        "typeLockThread": false,
+        "logsub": "",
+        "logtitle": "",
+        "bantitle": "",
+        "getfrom": "",
+        "reasons": []
+    },
-    "modMacros": "",
+    "modMacros": [],
    ...
-    "banMacros": ""
+    "banMacros": {
+        "banNote": "",
+        "banMessage": ""
+    }
}

@adhesivecheese
Copy link
Owner

Hey there! Apologies for the late reply here. Currently pmtw mirrors the setup created by toolbox, which does initialize those as blank strings. It looks like it should be fine to initialize them as empty lists, so as soon as I've got a chance to make sure that doesn't make anything misbehave I'll patch that!

Also, I'm super glad to know pmtw's getting some use!

adhesivecheese added a commit that referenced this issue Mar 3, 2023
Fix for #8. Needs Testing before committing.
@c0d3rman
Copy link

Same issue here. Just making the change in #10 didn't fix the issue; I still got:

File "/opt/homebrew/lib/python3.11/site-packages/pmtw/settings.py", line 27, in from_dict
    _banNote = str(obj.get("banNote"))

AttributeError: 'str' object has no attribute 'get'

I had a config page that looks like this:

{'ver': 1, 'domainTags': '', 'removalReasons': {'pmsubject': '', 'logreason': '', 'header': '', 'footer': '', 'removalOption': 'suggest', 'typeReply': 'pm', 'typeStickied': False, 'typeLockComment': False, 'typeAsSub': False, 'typeLockThread': False, 'logsub': '', 'logtitle': '', 'bantitle': '', 'getfrom': '', 'reasons': []}, 'modMacros': '', 'usernoteColors': '', 'banMacros': ''}

Following the steps suggested by @HaydenElza fixed it.

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

No branches or pull requests

4 participants