Skip to content

_unparseEntryRecord now handles OrderedDict #245

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

peppelinux
Copy link

No description provided.

@codecov
Copy link

codecov bot commented Oct 2, 2018

Codecov Report

Merging #245 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff           @@
##           master    #245   +/-   ##
======================================
  Coverage    71.1%   71.1%           
======================================
  Files          49      49           
  Lines        4818    4818           
  Branches      812     812           
======================================
  Hits         3426    3426           
- Misses       1056    1057    +1     
+ Partials      336     335    -1
Impacted Files Coverage Δ
Lib/ldif.py 75.96% <100%> (ø) ⬆️
Lib/ldap/controls/deref.py 57.14% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fb02c0...54c24f2. Read the comment docs.

@encukou
Copy link
Member

encukou commented Oct 2, 2018

Can you add a test to show the intended behavior and make sure it doesn't break in the future?

@peppelinux
Copy link
Author

It simply doesn't sort the values before processing
8a752f9#diff-384b211fbc9bab0d31d7e3fb02142ca2L153

This makes an ordereddict, or a simple dict, to be processed as is without reordering of its member.
Did I have well understand the question?

@encukou
Copy link
Member

encukou commented Oct 10, 2018 via email

@encukou
Copy link
Member

encukou commented Oct 10, 2018 via email

@peppelinux
Copy link
Author

peppelinux commented Oct 10, 2018 via email

@encukou
Copy link
Member

encukou commented Oct 11, 2018

Probably it should better to know why a dict should be sorted on its keys before processing?

On some of the Python versions python-ldap supports, dict order is unspecified or even random.
Alphabetical ordering means the LDAP writer gives consistent results. It avoids spurious diffs, allows naïve tests to work, and generally makes the output easier to work with.
Those advantages are not entirely lost in 3.6+. Attribute order is irrelevant in LDAP, so if you work with entries retrieved from a LDAP server, they'll be in unspecified order even if the Python has ordered dict.

I'd be fine with skipping the sorting for OrderedDict only – using OrderedDict is a nice explicit way to say you care about the order, and it's something you don't get directly from LDAP. (FWIW, cases like this are why OrderedDict is not deprecated in Python 3.6+.)

This patch works with dict and ordereddict and I'm using it in production environment.

Great! I'm glad python-ldap is helping!
Unfortunately we have many different production environments to think about, so getting the patches in isn't that simple.

Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

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

The change is going to break existing software that relies on the fact that LDIF Writer sorts output to minimize diffs. As @encukou mentioned in his comment ordinary dicts should be sorted. I'd be fine with special casing of collections.OrderedDict, though. This also needs a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants