Bug 54192 - Python 3 migration errors in OX app
Python 3 migration errors in OX app
Status: CLOSED MOVED
Product: Z_Internal OX development
Classification: Unclassified
Component: Generic
UCS 5.0 / 7.10.5
Other Linux
: P5 normal (vote)
: 7.10.5-ucs5
Assigned To: Alexander Steffen
Tobias Wenzel
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-12-06 08:47 CET by Daniel Tröder
Modified: 2022-10-26 11:23 CEST (History)
6 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 5: Major Usability: Impairs usability in key scenarios
Who will be affected by this bug?: 3: Will affect average number of installed domains
How will those affected feel about the bug?: 5: Blocking further progress on the daily work
User Pain: 0.429
Enterprise Customer affected?: Yes
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2022021021001397, 2022101121000406
Bug group (optional):
Max CVSS v3 score:


Attachments
ox-resource.py patch (828 bytes, patch)
2022-05-20 08:50 CEST, Tobias Wenzel
Details | Diff
manage_listerner_queue patch (261 bytes, patch)
2022-05-20 08:52 CEST, Tobias Wenzel
Details | Diff
patch for listener_tools.py (110 bytes, patch)
2022-05-20 14:16 CEST, Tobias Wenzel
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Tröder univentionstaff 2021-12-06 08:47:14 CET
See https://help.univention.com/t/upgrade-auf-ucs-5-ox/18871/8

-----------------------------------------------------------------------

raceback (most recent call last):
 File "/usr/lib/univention-directory-listener/system/ox-user.py", line 1119, in <module>
   handler.process_pending()
 File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 720, in process_pending
   return self.process(func)
 File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 764, in process
   entry = self._load_entry(timestamp)
 File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 829, in _load_entry
   return pickle.load(fd)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa1 in position 2: ordinal not in range(128)

-----------------------------------------------------------------------

Traceback (most recent call last):
  File "/usr/lib/univention-directory-listener/system/ox-resource.py", line 136, in <module>
    handler.process_pending()
  File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 720, in process_pending
    return self.process(func)
  File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 775, in process
    result = func(dn, entry.new, entry.old, entry.action)
  File "/usr/lib/univention-directory-listener/system/ox-resource.py", line 132, in handler
    ox_resource_listener = OXResourceListener(name, old, new)
  File "/usr/lib/univention-directory-listener/system/ox-resource.py", line 52, in __init__
    self.resource_name = self.get_resource_name()
  File "/usr/lib/univention-directory-listener/system/ox-resource.py", line 59, in get_resource_name
    return self.new['cn'][0].decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'

-----------------------------------------------------------------------

/usr/share/univention-ox/manage_listener_queue --list
Traceback (most recent call last):
  File "/usr/share/univention-ox/manage_listener_queue", line 266, in <module>
    sys.exit(main())
  File "/usr/share/univention-ox/manage_listener_queue", line 220, in main
    handler.collect_pickle_files()
  File "/usr/share/univention-ox/manage_listener_queue", line 160, in collect_pickle_files
    dn_s
TypeError: unsupported format string passed to bytes.__format__
Comment 1 Alexander Steffen univentionstaff 2022-01-04 12:58:31 CET
Issue:
See listed tracebacks by Daniel Tröder

Fix:
corrected code issues according to new python3 standards


fixed with branch: asteffen/54192-python3-migration-errors

requesting QA
Comment 2 Tobias Wenzel univentionstaff 2022-01-04 15:26:55 CET
QA:

Code review:

I have commented some remarks here 

https://git.knut.univention.de/univention/open-xchange/appsuite/-/commit/b3316c62bac8cb46d5f7ea644a01c1ced9fa2191
Comment 3 Tobias Wenzel univentionstaff 2022-01-06 11:28:28 CET
QA

The commit messages need a "#" 

 Bug 54192  -> Bug #54192

(I think this was a misunderstanding) please re-add the comment:

  # FIXME: default_context is int!


  File "/usr/share/univention-ox/manage_listener_queue", line 266, in <module>
    sys.exit(main())
  File "/usr/share/univention-ox/manage_listener_queue", line 220, in main
    handler.collect_pickle_files()
  File "/usr/share/univention-ox/manage_listener_queue", line 156, in collect_pickle_files
    ox_module.rjsut(8),
AttributeError: 'str' object has no attribute 'rjsut'


-> after your fix, if resolve the bug, so the QA knows it's time to continue.
Comment 4 Alexander Steffen univentionstaff 2022-01-07 09:42:24 CET
fixed typo in manage_listener_queue, readded comment in ox-resource.py

https://git.knut.univention.de/univention/open-xchange/appsuite/-/commit/78f1a4af83c33d45ed5db4caa1f70cfdae6fea2b
Comment 5 Tobias Wenzel univentionstaff 2022-01-11 16:31:42 CET
QA: looks good. reopen for final steps.


could you please explain again, why replaced

'{} | {:8} | {} | {:18} | {}{}'
with 
"%s | %s | %s | %s | %s%s"


- Don't forget the `#` in the commit message and to change to something like "fix python3 migration errors".


When you do your squashing, please add the spaces (revert) to keep the git diff small

 #FIXME: default_context is int!


After that you can squash, merge & build. Ask me, if you need help with that.
Comment 6 Alexander Steffen univentionstaff 2022-01-18 09:35:49 CET
All requestes changes by Tobias Wenzel where added.

Cherry-picked and merged the branch into 5.0


Successful build
Package: univention-ox
Version: 12.0.25A~5.0.0.202201180917
Branch: ucs_5.0-0
Scope: oxse4ucs
Comment 7 Tobias Wenzel univentionstaff 2022-01-18 09:41:08 CET
QA: all OK -> verify

OK code
OK changelog 
OK merge
OK script is working
Comment 8 Florian Best univentionstaff 2022-01-31 16:33:03 CET
REOPEN:
univention-ox/listener/ox-resource.py
* get_resource_name() returns mixed bytes/str
* self.old_context_id and self.new_context_id is assigned to different types (bytes vs str) - depends on if the attribute is set or not
* `__package__ = ''  # workaround for PEP 366` was not removed, like explained in the Dev-Doc.
* self.resource_name is of type bytes but this is given to string formatting in remove_resource()

univention-ox/share/manage_listener_queue:
* collect_pickle_files(): a unnecessary f-string has been commited, which is also not Python 2 compatible (don't know if the app is also released for py2).
* collect_pickle_files(): looks like a byte string (variable "name") is mixed into options_str.
I say looks like because I don't know if the other OX-classes are changing old and new to contain strings instead of bytestrings - which if yes would probably be wrong as the encoding depends on the specific attribute.
Comment 9 Christina Scheinig univentionstaff 2022-02-14 17:07:46 CET
I am thinking to increase the pain, because the "rejected" user cannot use/login in the appsuite.

Ein Benutzer mit der ID "usupport" konnte nicht im Kontext 10 gefunden werden. (USR-0015)

I see in the listener.log 

08.02.22 12:49:44.237  LISTENER    ( PROCESS ) : updating 'uid=usupport,ou=New,ou=Mitarbeiter,ou=Neu,dc=schein,dc=de' command a
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 728, in wrapper
    return self.process(func)
  File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 764, in process
    entry = self._load_entry(timestamp)
  File "/usr/lib/python3/dist-packages/univention/ox/listener_tools.py", line 829, in _load_entry
    return pickle.load(fd)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa1 in position 2: ordinal not in range(128)


The listener then tries to add the user 3 more time with the same traceback
Comment 10 Christina Scheinig univentionstaff 2022-02-14 17:08:37 CET
univention-app info
UCS: 5.0-1 errata218
Installed: mailserver=12.0 open-xchange-guard=2.10.5-ucs1 open-xchange-text=7.10.5-ucs1 oxseforucs=7.10.5-ucs4 samba4=4.13
Upgradable:

apt-cache policy open-xchange
open-xchange:
  Installiert:           7.10.5-38

Sorry forgot
Comment 11 Alexander Steffen univentionstaff 2022-02-16 12:53:36 CET
fixes: fixed mixed return-types and removed the workaround for PEP 366 which is not needed anymore.

fixed with branch: 54192-python3-migration-errors-v2

requesting QA

@Christina Scheinig: with the implemented fixes, I was not able to reproduce the behaviour anymore.
Comment 12 Tobias Wenzel univentionstaff 2022-03-02 16:38:23 CET
QA:

looks good.
please squash, merge & build.
Comment 13 Alexander Steffen univentionstaff 2022-03-04 09:37:20 CET
Successful build
Package: univention-ox
Version: 12.0.27A~5.0.0.202203040936
Branch: ucs_5.0-0
Scope: oxse4ucs
Comment 14 Tobias Wenzel univentionstaff 2022-03-04 09:42:29 CET
QA: All OK verified
Comment 15 Christina Scheinig univentionstaff 2022-05-11 11:04:03 CEST
When is a new appversion with this fix scheduled?
Comment 16 Christina Scheinig univentionstaff 2022-05-11 15:20:53 CEST
I increased the pain again, because new user cannot use the appsuite, so e-mail workaround is thunderbird but no calender and addressbook for the user.
Comment 17 Tobias Wenzel univentionstaff 2022-05-12 13:02:27 CEST
I'm very sorry. This should have been released with 7.10.5-ucs5, but (I guess) it was missed due to a missing entry in the update notes.

It will be released with the next version - sorry, I can't tell you a date.
Comment 18 Florian Best univentionstaff 2022-05-12 13:17:39 CEST
(In reply to Tobias Wenzel from comment #17)
> I'm very sorry. This should have been released with 7.10.5-ucs5, but (I
> guess) it was missed due to a missing entry in the update notes.
> 
> It will be released with the next version - sorry, I can't tell you a date.

REOPEN: Then please add the entry into the update notes.
Comment 19 Florian Best univentionstaff 2022-05-12 13:18:13 CEST
and please set a Target Milestone for every bug which you RESOLVE/VERIFY.
Comment 20 Tobias Wenzel univentionstaff 2022-05-12 15:11:15 CEST
added target milestone, update notes have been adapted in 

[5.0] aa699768 Bug #54192: add update entry
Comment 21 Christina Scheinig univentionstaff 2022-05-12 16:21:47 CEST
Could you please provide a patch, the customer can apply, so the new users can work with OX?
Comment 22 Tobias Wenzel univentionstaff 2022-05-20 08:50:25 CEST
Created attachment 10954 [details]
ox-resource.py patch
Comment 23 Tobias Wenzel univentionstaff 2022-05-20 08:52:27 CEST
Created attachment 10955 [details]
manage_listerner_queue patch
Comment 24 Tobias Wenzel univentionstaff 2022-05-20 09:18:42 CEST
Copy the patches to your UCS system apply the patches like so: 


(In reply to Tobias Wenzel from comment #22)
> Created attachment 10954 [details]
> ox-resource.py patch


patch /usr/share/univention-ox/listener/ox-resource.py < /tmp/ox-resource.py.patch


(In reply to Tobias Wenzel from comment #22)
> Created attachment 10955 [details]
> manage_listerner_queue patch


patch /usr/share/univention-ox/manage_listener_queue /tmp/manage_listener_queue.patch
Comment 25 Tobias Wenzel univentionstaff 2022-05-20 14:16:08 CEST
Created attachment 10956 [details]
patch for listener_tools.py

patch /usr/lib/python3/dist-packages/univention/ox/listener_tools.py < /tmp/listener_tools.py
Comment 26 Tobias Wenzel univentionstaff 2022-05-20 14:17:37 CEST
set to resolve/ moved: 

i added changes for the listener_tools.py in https://git.knut.univention.de/univention/open-xchange/appsuite/-/merge_requests/3/diffs#ac04d381579ac0ae332ce6f713fc73d1124f9938

this has to be qa't as well.
Comment 27 Tobias Wenzel univentionstaff 2022-05-24 08:32:13 CEST
Package: univention-ox
Version: 12.0.28A~5.0.0.202205240829
Branch: ucs_5.0-0
Scope: oxse4ucs


[5.0] 0d617637 Bug #54192: migrate listener_tools.py

changelog:

Bug #54192: python3 migration: use byte encoding to load pickle file
Comment 28 Christina Scheinig univentionstaff 2022-10-11 13:06:18 CEST
I now, have the third customer, with a support ticket, who is not able to apply the patches!
Comment 29 Daniel Tröder univentionstaff 2022-10-26 11:23:43 CEST
Released with OX app version 7.10.6-ucs1.